Closed xtagon closed 7 years ago
@xtagon I'm glad you are enjoying ember-data-url-templates
Problem is, I don't want to hard-code each relative link by modifying the payload.
I don't have an ideal solution to the problem you are describing. I personally also use the links
technique (although I frequently have my server add the links
attribute).
I would rather just use ember-data-url-templates and have Ember assume there is a relationship if the template exists.
The problem, for ember-data-url-templates, is that ember-data does not make any calls to the adapter when a relationship has neither links
or some ids.
Alternatively, I would like some way to expand/render the template myself while I add links (but the former method would be better)
You can always use UriTemplate
directly.
I'm not sure which would work the best, but here are a few ideas on how to handle relationships with ember-data-url-templates:
Have ember-data-url-templates actually add links
This seems pretty error prone. Normally, as you did, this would happen in the serializer, but it seems pretty weird to need to include ember-data-url-templates in your serializer...
Doing this in the adapter would be possible, but probably error prone.
Change the ember-data store to make call on the adapter when it doesn't have any ids to load for the relationship and it also doesn't have links
I don't know if it is possible for an addon to monkey-patch the store, so this would probably require making a change to ember-data itself. I'm not sure how this would work.
I'd like to leave this issue open for reference and as a place for discussion.
@rmharrison You might also be interested in this discussion :)
Have ember-data-url-templates actually add links
This seems pretty error prone. Normally, as you did, this would happen in the serializer, but it seems pretty weird to need to include ember-data-url-templates in your serializer...
Weirder than hard-coding links in the serializer, which is really the only other thing to do when the server doesn't provide links?
Update: I'd like to address this by resolving https://github.com/emberjs/data/issues/2162.
@xtagon Would this still be useful to you?
As part of working on emberjs/data#2162, I'm taking some extra time to document how this works.
At work, we're actually adding links
in the serializer, so I thought I would try implementing your suggestion in ember-data-url-templates.
Do you have time to evaluate https://github.com/amiel/ember-data-url-templates/pull/36 ?
It would be great to get a second set of eyes on it since it is such a big change...
@amiel This would still be useful and I'll be happy to give #36 a try. We're still adding links in the serializer at work as well.
Hi,
I'm loving ember-data-url-templates, thanks for making it!
My REST serializers are for a non-standard API, and I find myself needing to override normalize response functions to add links to the data. If I don't add links in the serializer, Ember-Data will not recognize that there is a has many relationship.
Problem is, I don't want to hard-code each relative link by modifying the payload. I would rather just use ember-data-url-templates and have Ember assume there is a relationship if the template exists. Alternatively, I would like some way to expand/render the template myself while I add links (but the former method would be better)
What is the recommended way to accomplish this?
Thanks in advance!