Merge pull request #204 from cardoso/master

Add Filter NodeConvertible conformance documentation
This commit is contained in:
Tanner 2017-08-10 10:34:30 -04:00 committed by GitHub
commit 5ac8679e57
1 changed files with 38 additions and 0 deletions

View File

@ -165,6 +165,44 @@ Raw filters can be used to filter by values that should not be parameterized.
try query.filter(raw: "date >= CURRENT_TIMESTAMP")
```
### NodeConvertible Conformance
Filters can be converted to and from Node objects, which allows filters to be specified via JSON and other NodeRepresentable formats. This makes it very easy if you want to allow a consumer API to filter your entities.
Example:
```json
{
"entity":"MyApp.User",
"method":{
"type":"group",
"relation":"and",
"filters":[
{
"entity":"MyApp.User",
"method":{
"type":"compare",
"comparison":"greaterThanOrEquals",
"field":"age",
"value":18
}
},
{
"entity":"MyApp.User",
"method":{
"type":"compare",
"comparison":"equals",
"field":"gender",
"value":"male"
}
}
]
}
}
```
!!! note
You must include the module name in the entity field. "MyModule.MyEntity"
## Distinct
To select only distinct models from the database, add `.distinct()` to your query.