keystonejs/keystone — pull request #609 by JohnnyEstilles (2014-09-03 19:05:47+00:00)
Title: Enhancing relationship filters

This PR was inspired by a question posted by [Ignacio Lago](http://stackoverflow.com/users/196931/ignacio-lago) on StackOverflow in which he inquired about [Filtering relationships by id](http://stackoverflow.com/questions/25641373/filter-keystonejs-relationship-by-id).

I thought the use case he described was quite interesting, so I decided to prepare this PR.

The syntax of this new feature is identical to filtering by another field in the model, by preceding `_id` with a colon. Below is a somewhat silly example to illustrate the use of this feature. For a more realistic example, please see Ignacio Lago's [question on StackOverflow](http://stackoverflow.com/questions/25641373/filter-keystonejs-relationship-by-id).

```js
User.add({
...
awsomePost: { Types.Relationship, ref: 'Post', filter: { author: ':_id' } },
...
});
```

Previously, filtering by fields (using the colon prefix) only worked with `Types.Select` and `Types.Relationship` fields. In this PR I expanded this list to include any field that is rendered with an `input` element, including `Types.Text`, `Types.Boolean`, `Types.Number`, `Types.Currency`, and `Types.Date`, using exactly the same syntax.

And ... since this option hadn't been officially documented yet, I decided to throw in some docs as well.

As usual, comments, suggestions and constructive criticism is always welcome. :-)