Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included type seems broken #10

Open
lancedikson opened this issue Jul 18, 2018 · 0 comments
Open

Included type seems broken #10

lancedikson opened this issue Jul 18, 2018 · 0 comments

Comments

@lancedikson
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant