Skip to content

Included type seems broken #10

@lancedikson

Description

@lancedikson

The setting:

I have two serializers: Product and ProductShopVideo.

// file JsonApiViews/V1/Product.js
class Product extends JsonApiView {
  get attributes() {
    return [
      'title',
      'sku',
      // ... some more attrs here, doesn't really matter
      'active'
    ];
  }

  productShopVideos() {
    return this.hasMany('App/Http/JsonApiViews/V1/ProductShopVideo', {
      included: true,
      excludeRelation: 'product',
      ref: '_id'
    })
  }
}
// file JsonApiViews/V1/Product.js
class ProductShopVideo extends JsonApiView {
  get attributes() {
    return [
      "addedDate" ,
      "deletedBy" ,
      "deleted" ,
      "addedBy" ,
      "disabled"
    ];
  }

  product() {
    return this.belongsTo('App/Http/JsonApiViews/V1/Product', {
      ref: 'product'
    });
  }
}

The result I recieve using proper data and the Product serializer is:

{
    "meta": {},
    "included": [
        {
            "type": "productShopVideos",
            "id": "5b432fd15c242f0458c15a9d",
            "attributes": {}
        }
    ],
    "data": {
        "type": "product",
        "id": "5b432fd05c242f0458c15a9a__499",
        "attributes": {},
        "relationships": {
            "product-shop-videos": {
                "data": [
                    {
                        "type": "productShopVideos",
                        "id": "5b432fd15c242f0458c15a9d"
                    }
                ]
            }
        }
    }
}

I removed attributes for both to make it a bit clear. As you can see, the type for ProductShopVideo in included is not relevant. It should be kebab-cased as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions