-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE ds-serialize-ids-and-types] Create a new
ids-and-types
emb…
…edding strategy for non STI polymorphic hasMany Taking as example this scenario: ```js User = DS.Model.extend({ name: DS.attr('string'), pets: DS.hasMany('pet', { polymorphic: true }) }); Pet = DS.Model.extend({ name: DS.attr('string'), }); Cat = Pet.extend({ // ... }); Parrot = Pet.extend({ // ... }); ``` As of today, when using the `DS.EmbeddedRecordsMixin` in a serializer and configuring the serialization stategy like this: ``` attrs: { pets: { serialize: 'ids' } } ``` The relationship is serialized: ```json { "user": { "id": "1" "name": "Bertin Osborne", "pets": [1,2] } } ``` This works ok if the polymorphism is based on STI, but that is just one specific implementation does not cover all use cases. Probably when a hasMany relationship is polymorphic the serialization should generate an array of object containing `id` and `type` by default, but at this point this can't be changed because it would break apps in the wild. Because of that a new serialization strategy named `ids-and-types` has been created that covers this use case. Probably this should become the default behavior of the `ids` strategy in ember 3.0, but not for now. For the same example above, this stragegy would generate the following payload: ```js { "user": { "id": "1" "name": "Bertin Osborne", "pets": [ { "id": "1", "type": "Cat" }, { "id": "2", "type": "Parrot"} ] } } ``` Note that with this strategy if the differenty type of records don't whare the same ids space, that is not a problem. ```js { "user": { "id": "1" "name": "Bertin Osborne", "pets": [ { "id": "1", "type": "Cat" }, { "id": "1", "type": "Parrot"} // Same id, but different type ] } } ```
- Loading branch information
Showing
4 changed files
with
175 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters