Skip to content

Conversation

@stefanvanherwijnen
Copy link
Contributor

@stefanvanherwijnen stefanvanherwijnen commented Aug 2, 2019

Currently by default all relationship objects are included (i.e. they are in the included top-level key). For one-to-one relations the alternativeKey can be used to still define the relation without including the whole object, but for a many-to-many relation this is not possible. My suggestion is to not include objects which only have an id. This way the relationships are still defined in the relationships key, but the (empty) data is not included.

Currently the empty data is still included, but the data is empty (obviously).

(also fixed #77)

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling c4bd7bc on stefanvanherwijnen:relationship into 19c810b on danivek:master.

@danivek
Copy link
Owner

danivek commented Aug 5, 2019

I don't see any recommendation about this on JSON:API specification

Quite similar to these threads:

@stefanvanherwijnen
Copy link
Contributor Author

Not entirely.
Suppose a product belongs to a category which has a certain prices at different dates. I.e. there is a hasMany relation for prices on the product. The only way to populate relationships is by actually loading the related prices, as there is no direct key to access them.

Currently if there is a prices key set on the product data, the price is also included in included, even if the prices key only contains an id. For the category the relation is defined by the category_id on a product, so this relation is set but the data is not included.

Now that I think of it, the proper way to achieve this is by setting prices to an array of ID's.

Still, an empty attributes value does not make sense but I can't really find in the specification how to handle it either.

@danivek danivek closed this in 66f19e5 Aug 21, 2019
alechirsch pushed a commit to alechirsch/json-api-serializer that referenced this pull request Dec 10, 2019
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

Successfully merging this pull request may close these issues.

Null as data in _convertCase throws an error

3 participants