Closed amiel closed 7 years ago
Thanks for opening this PR, I will be testing it out when I get a chance 👍
@amiel This branch works perfectly in my own app and I was easily able to transition away from adding links to my serializers. Thanks so much!
I referenced in my package.json
like this:
"ember-data-url-templates": "github:amiel/ember-data-url-templates#feature/support-relationship-urls",
Looking forward to a release 👍
@xtagon Thank you for testing it out. I'll work on a release today.
Thanks again @amiel :-)
@amiel I've a slightly different requirement. If the server returns the links, but I need to append some extra params along with the link returned by the server in order to fetch the association data, can I just modify the model to specify the url template, and update my adapter to add the params, but skip the mix in into serializer or is the mixin necessary to be included in the serializer??
@dyoganand If you want to use this feature, mixing in the serializer is required.
For your use-case, it might make sense to custom update the links
in your serializer. My blog post on how this feature works might help.
This allows using a url template to load a relationship even if that relationship does not already have
data
orlinks
.For some more background on the details of this, check out my blog post on How Ember Data Loads Async Relationships.
I believe this should resolve #29.
Usage
Using this feature will require making changes to a model, serializer, and adapter.
Let's use an example from the acceptance tests. We have a
posts
model thathasMany
reactions and we want to load the reactions with a url template.To do this, we need to make changes to the
post
model,post
serializer, andpost
adapter.In the
post
model, we opt-in to using a url template to load the relationship by adding theurlTemplate
option tohasMany
.In the
post
serializer, we need to mix in theUrlTemplatesSerializer
.In the
post
adapter, we can specify the url template.Note that the attribute name for the url template (
reactionsUrlTemplate
) matches the option provided in the options tohasMany
({ urlTemplate: 'reactions' }
).