Skip to content
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

queryRecord is not guaranteed to return a single record #3977

Closed
bcardarella opened this issue Dec 8, 2015 · 4 comments
Closed

queryRecord is not guaranteed to return a single record #3977

bcardarella opened this issue Dec 8, 2015 · 4 comments
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@bcardarella
Copy link
Contributor

https://github.com/emberjs/data/blob/master/addon/system/store/finders.js#L193

push returns a single model for objects and an array of records for arrays, so if the response is a collection of records instead of a single record the result of queryRecord will be a collection. The documentation implies that this function will always return a single record.

If the position of the ember-data team is to say "the endpoint should return a single record" I'd like to challenge this.

The url being built by queryRecord is identical to the one being built by query. From the backend's perspective there may be little control over how to shape the response, even if we assume one of the query criteria to force a unique response. I would advocate for queryRecord to force a collection from push to return firstObject.

@fivetanley
Copy link
Member

I agree.

@fivetanley fivetanley added the Bug label Dec 8, 2015
@bcardarella
Copy link
Contributor Author

@fivetanley I can put together a PR for this. Should I target different versions or just master?

@fivetanley
Copy link
Member

Just master and I'll let you know if it doesn't cleanly apply to beta.

@bcardarella
Copy link
Contributor Author

We must have something else going on, it appears that normalizeSingleResponse will force all records not firstObject into the included key which satisfies this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

No branches or pull requests

3 participants