-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow include
query parameter with store.findRecord & store.findAll
#3976
Conversation
I think copying into
I was originally against this because I think it would be more consistent if the API only accepted 1 type. However, @igorT convinced me that allowing the value to be an array could allow Ember Data to be smarter and warn if an included relationship was not defined on the model. |
I agree with @bmac |
const adapterOptions = snapshotRecordArray.adapterOptions || {}; | ||
const { include } = adapterOptions; | ||
|
||
let query; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind refactoring some of the duplicated code in findRecord
and findAll
into a helper method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
@HeroicEric Do you mind wrapping all your changes in feature flags? |
97193d0
to
4f05ca9
Compare
include
query parameter with store.findRecord & store.findAllinclude
query parameter with store.findRecord & store.findAll
include
query parameter with store.findRecord & store.findAllinclude
query parameter with store.findRecord & store.findAll
@bmac I tried wrapping the changes in a feature flag but I'm not sure I did all the steps correctly. The feature flagged tests don't seem to run with or without the Edit: Nevermind. Figured it out. Features aren't meant to be inside a |
@@ -56,7 +57,7 @@ test("find - basic payload", function(assert) { | |||
run(store, 'find', 'post', 1).then(assert.wait(function(post) { | |||
assert.equal(passedUrl, "/posts/1"); | |||
assert.equal(passedVerb, "GET"); | |||
assert.equal(passedHash, undefined); | |||
assert.deepEqual(passedHash.data, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be preferred to continue returning undefined
rather than {}
in these cases? adapter.ajax
seems to act the same with { data: {} }
and {}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
returning {}
seems ok to me.
6faed41
to
36b22de
Compare
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`.
36b22de
to
266d3b0
Compare
Rebased, updated the description, added the feature flag to |
Allow `include` query parameter with store.findRecord & store.findAll
🎉 |
This commit adds documentation on the use of the `include` query parameter in `DS.Store` methods `findRecord()` and `findAll()`. This feature allows records of models related to those requested to be retrieved from JSON API compliant server in a single request. This capability was added in emberjs#3976 but is not currently documented.
This commit adds documentation on the use of the `include` query parameter in `DS.Store` methods `findRecord()` and `findAll()`. This feature allows records of models related to those requested to be retrieved from JSON API compliant server in a single request. This capability was added in emberjs#3976 but is not currently documented.
Related RFC: emberjs/rfcs#99
Description
These changes allow an
include
parameter to be specified when usingstore.findRecord
andstore.findAll
:The value for
include
is copied onto theDS.Snapshot
orDS.SnapshotRecordArray
that is passed to the corresponding adapterfunction. This value is then pulled from the snapshot and used as a
query parameter (
include
) when making an AJAX request viaadapter.ajax
.Questions
Is it OK that theinclude
option is copied intoadapterOptions
or should it be copied intoadapterOptions.query
. I originally copied it intoadapterOptions.query
but the code was a little uglier so I went with just copying it intoadapterOptions
, but I'm still not sure.include
is an array, should we automatically join the values into a comma separated list? The JSON API spec for "Inclusion of Related Resources" requires that the value be a comma separated list but I didn't think that was necessarily what everyone would want. We could just do that in the JSON API adapter but I figured I'd ask for some feedback before proceeding with that.Work to be done in additional PRs
It was also mentioned in the RFC that we could provide some additional functionality:
I'm not totally clear on what the behavior would be there yet so those were left unimplemented for now.