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

Can't filter by id #18

Open
ghost opened this issue Mar 9, 2016 · 10 comments
Open

Can't filter by id #18

ghost opened this issue Mar 9, 2016 · 10 comments

Comments

@ghost
Copy link

ghost commented Mar 9, 2016

The filter is ok, unless you try to filter by the id.

I received this exception.

Unhandled rejection BadRequestError: The field "id" is non-existent.

@gr0uch
Copy link
Member

gr0uch commented Mar 10, 2016

This is expected, I think. Why are you trying to "filter" by ID? If you have the ID of a record, the URL always looks like this:

/:type/:id

Not sure what the use case is.

@ghost
Copy link
Author

ghost commented Mar 10, 2016

It's used by Ember to load relationships without making a request for every relationship.

In the adapter we can set the coalesceFindRequests option to true, so we can get all in one request:

{
  post: {
    id: 1,
    comments: [1, 2]
  }
}

With this option set to false the request will be:

GET /comments/1
GET /comments/2

And with the option set to true:

GET /comments?filter[id]=1,2

@gr0uch
Copy link
Member

gr0uch commented Mar 10, 2016

Oh, ok. This is an odd case because the JSON API spec says nothing about the filter query, but it seems that they rely on non-standard features. So in the special case when IDs are not in the route and filter[id] is present, it should actually change the requested IDs.

@ghost
Copy link
Author

ghost commented Mar 11, 2016

I don’t think that this is a non-standard feature, it’s likely that is an implicit implementation because the filter must filter any column, independent if is primary key or not.

If I figure out how to implement this, i’ll make a pull request.

Iago Sousa
iagosousa@icloud.com

On Mar 10, 2016, at 2:02 PM, ████ notifications@github.com wrote:

Oh, ok. This is an odd case because the JSON API spec says nothing about the filter query, but it seems that they rely on non-standard features. So in the special case when IDs are not in the route and filter[id] is present, it should actually change the requested IDs.


Reply to this email directly or view it on GitHub #18 (comment).

@gr0uch
Copy link
Member

gr0uch commented Mar 11, 2016

The spec says absolutely nothing about filtering:

JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

http://jsonapi.org/format/#fetching-filtering

So the fact that Ember Data uses the filter query at all is non-standard.

@ghost
Copy link
Author

ghost commented Mar 11, 2016

The filter query parameter is reserved for filtering data. Servers and clients SHOULD use this key for filtering operations.
JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

The problem is that the filter can be applied to any column except ID, that is also a column.

Seems that the script is ignoring the ID as a column.

Iago Sousa
iagosousa@icloud.com

On Mar 11, 2016, at 2:25 PM, ████ notifications@github.com wrote:

The spec says absolutely nothing about filtering:

JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

http://jsonapi.org/format/#fetching-filtering http://jsonapi.org/format/#fetching-filtering
So the fact that Ember Data uses the filter query at all is non-standard.


Reply to this email directly or view it on GitHub #18 (comment).

@gr0uch
Copy link
Member

gr0uch commented Mar 11, 2016

What I meant was that any sort of filtering is out of the spec, and is ad hoc. For example, if I wanted to filter by aggregate sum of an array of numbers greater than some amount, of course the spec won't bother with that. Any client using the filter option is effectively coupled to a particular implementation.

I think that this discussion should belong in JSON API.

@ghost
Copy link
Author

ghost commented Mar 11, 2016

Oh yes, sorry for the misunderstanding.

Iago Sousa
iagosousa@icloud.com

On Mar 11, 2016, at 2:43 PM, ████ notifications@github.com wrote:

What I meant was that any sort of filtering is out of the spec, and is ad hoc. For example, if I wanted to filter by aggregate sum of an array of numbers greater than some amount, of course the spec won't bother with that. Any client using the filter option is effectively coupled to a particular implementation.

I think that this discussion should belong in JSON API.


Reply to this email directly or view it on GitHub #18 (comment).

@ghost
Copy link
Author

ghost commented Mar 11, 2016

This is a server strategy and does not rely on specification.

@ghost ghost closed this as completed Mar 11, 2016
@gr0uch
Copy link
Member

gr0uch commented Mar 11, 2016

Actually leave it open, I would like to keep track of it since it's useful for Ember Data.

@gr0uch gr0uch reopened this Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@gr0uch and others