Repository navigation
Allow query parameters to be specified when finding records via Ember Data's Store - #99
HeroicEric wants to merge 2 commits into
Conversation
Improve support for JSON API's: Inclusion of Related Resources - http://jsonapi.org/format/#fetching-includes Sparse Fieldsets - http://jsonapi.org/format/#fetching-sparse-fieldsets
There was a problem hiding this comment.
before adapterOptions were attached to the snapshot we considered passing adapterOptions into findRecord as an extra argument. In the end we decided to attach it to the snapshot in order to make it work with colaced requests.
I think we should follow the same pattern here and copy query into adapterOptions.query. This means
const articles = this.store.findAll('article', {
query: {
include: 'comments'
}
});would be equivalent to
const articles = this.store.findAll('article', {
adapterOptions: {
query: {
include: 'comments'
}
}
});There was a problem hiding this comment.
Nice! I wasn't aware that those were already being passed via the snapshot. I'll update the RFC.
There was a problem hiding this comment.
@bmac I just updated this to nest query under adapterOptions in the examples but I think I just realized that you were suggesting to keep query as the as option to findRecord but inside findRecord copy the query over to adapterOptions.
So the api would still be something like:
this.store.findRecord('post', 1, {
query: {
include: 'author'
}
});but that query would be copied over into adapterOptions before the snapshot is created and sent to the adapter. Is that what you meant?
|
It would also be useful to be able to supply this.store.peekRecord('foo', 1).get('bars', {
adapterOptions: {
include: 'quuxes'
}
});And/or when defining relationships: // app/models/foo.js
import DS from 'ember-data';
export default DS.Model.extend({
bars: DS.hasMany('bar', {
adapterOptions: {
include: 'quuxes'
}
})
}); |
|
Hi @HeroicEric I'm a little weary about the potential for the query parameter to load a record in an incomplete state. My fear is that a record may be loaded into the store with fields missing when visiting one route then retrieved from the cache when the user navigates to a new route. I would like to start with a more conservative API that only exposes the ability to specify the const article = this.store.findRecord('article', 1, { include: 'comments' });
const articles = this.store.findAll('article', { include: 'comments' });
article.save({ include: 'comments' });
article.destroyRecord({ include: 'comments' });This still has the potential for the same problem of expected relationship data not being loaded when loading a record from the cache, however, Ember Data has better tools (namely async relationships) for dealing with this case then it has for partially loaded fields. |
|
That sounds great to me, @bmac. Thoughts on extending that functionality to relationship fetching? Have you seen the ember-data-has-many-query add-on? |
|
I would love a official ember way to query data with a cache. It hacks into the store and asks Something to notice: Think about how to handle with pagination and infinity-scroll. |
Related RFC: emberjs/rfcs#99 These changes allow an `include` paremeter to be specified when using `store.findRecord` and `store.findAll`: ```javascript store.findRecord('post', 123, { include: 'comments' }); store.findAll('post', { include: 'comments' }); ``` The value for `include` is copied into the `adapterOptions` that are passed to the corresponding adapter function as part of the `snapshot` or `snapshotRecordArray`. This value is then pulled from the snapshot and used as a query parameter (`include`) when making an AJAX request via `adapter.ajax`.
Related RFC: emberjs/rfcs#99 These changes allow an `include` paremeter to be specified when using `store.findRecord` and `store.findAll`: ```javascript store.findRecord('post', 123, { include: 'comments' }); store.findAll('post', { include: 'comments' }); ``` The value for `include` is copied into the `adapterOptions` that are passed to the corresponding adapter function as part of the `snapshot` or `snapshotRecordArray`. This value is then pulled from the snapshot and used as a query parameter (`include`) when making an AJAX request via `adapter.ajax`.
Related RFC: emberjs/rfcs#99 These changes allow an `include` paremeter to be specified when using `store.findRecord` and `store.findAll`: ```javascript store.findRecord('post', 123, { include: 'comments' }); store.findAll('post', { include: 'comments' }); ``` The value for `include` is copied into the `adapterOptions` that are passed to the corresponding adapter function as part of the `snapshot` or `snapshotRecordArray`. This value is then pulled from the snapshot and used as a query parameter (`include`) when making an AJAX request via `adapter.ajax`.
Related RFC: emberjs/rfcs#99 These changes allow an `include` paremeter to be specified when using `store.findRecord` and `store.findAll`: ```javascript store.findRecord('post', 123, { include: 'comments' }); store.findAll('post', { include: 'comments' }); ``` The value for `include` is copied onto the `DS.Snapshot` or `DS.SnapshotRecordArray` that is passed to the corresponding adapter function. This value is then pulled from the snapshot and used as a query parameter (`include`) when making an AJAX request via `adapter.ajax`.
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // Create let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); // POST /posts // // data: { // post: { title: 'Hurray' }, // include: 'author' // } ``` ```javascript // Update let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); // PUT /posts/123 // // data: { // post: { title: 'Hurray' }, // include: 'comments' // } ``` ```javascript // Update let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); // DEL /posts/123 // // data: { // post: { title: 'Hurray' }, // include: 'comments' // } ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
Fixes warp-drive-data#4344 This allows an `include` parameter for be specified when creating, updating, or deleting a model. This feature was originally discussed in emberjs/rfcs#99 but was not part of the initial implementation. Examples: ```javascript // POST /posts?include=author let post = this.store.createRecord('post', { title: 'Hurray' }); post.save({ include: 'author' }); ``` ```javascript // PUT /posts/123?include=comments let post = this.store.peekRecord('post', 123); set(post, 'title', 'Hurray'); post.save({ include: 'comments' }); ``` ```javascript // DEL /posts/123?include=comments let post = this.store.peekRecord('post', 123); post.deleteRecord(); post.save({ include: 'comments' }); ```
|
This was added in warp-drive-data/warp-drive#3976 |
Rendered