amiel / ember-data-url-templates

an ember-addon to allow building urls with url templates instead of defining buildURL
https://github.com/amiel/ember-data-url-templates/wiki
MIT License
129 stars 22 forks source link

Support DS.Snapshot #34

Closed amiel closed 7 years ago

amiel commented 7 years ago

This allows url templates to use attributes from the snapshot as well as relationship ids.

For example, assuming the following models:

// app/models/post.js
slug: attr('string'),
comments: hasMany(),

// app/models/comment.js
post: belongsTo(),

Then the following is now possible, but only for adapter hooks that take a snapshot:

// app/adapters/post.js
urlTemplate: "/api/posts{/slug}", // This used to work before DS.Snapshot, now only id works

// app/adapters/comment.js
urlTemplate: "/api/posts/{postId}/comments{/id}", // either postId or post_id will work, automatically using the id from the associated post