json-api/json-api — pull request #293 by krainboltgreene (2014-10-16 12:48:58+00:00)
Title: Prefixed filter queries are easier to parse

So I'm implementing the filter mechanic and I realized the annoyance I would have to go through in order to make it work.

In simple use cases the filtering mechanic is arguably simple to parse:

```
GET /comments?post=1
```

``` ruby
Comment.where(post: params["post"])
```

However scaling this to both multiple endpoints and with multiple includes becomes...cumbersome:

```
GET /profiles?account=1&age=23&visible=true&include=posts,comments&fields=id
```

``` ruby
models = Profile.where(account: params["account"], age: params["age"], visible: params["visible"]).includes(params["includes"].split(","))
models.map(&:to_hash).map { |hash| hash.slice(params["fields"].split(",")) }
```

The natural inclination is to mimic the other areas as demonstrated above, but it's not practical to parse. I propose with this pull request that we mimic the already established way of doing complex filters:

```
GET /profiles?filter[account]=1&filter[age]=23&filter[visible]=true&include=posts,comments&fields=id
```

``` ruby
models = Profile.where(params["filter"]).includes(params["includes"].split(","))
models.map(&:to_hash).map { |hash| hash.slice(params["fields"].split(",")) }
```