Refactored codes to not modify get-config-for-method.test.js, moved validationAssociations definition logic from get-config-for-method.js to crud.js, fixed README.md
This commit is contained in:
16
README.md
16
README.md
@ -92,13 +92,25 @@ It's easy to restrict your requests using Sequelize's `where` query option. Just
|
||||
Team.findOne({ where: { city: 'windsor' }})
|
||||
```
|
||||
|
||||
You can also do more complex queries by setting the value of a key to JSON.
|
||||
|
||||
```js
|
||||
// returns only teams that have a `address.city` property of "windsor"
|
||||
// GET /team?city={"address": "windsor"}
|
||||
// or
|
||||
// GET /team?city[address]=windsor
|
||||
|
||||
// results in the Sequelize query:
|
||||
Team.findOne({ where: { address: { city: 'windsor' }}})
|
||||
```
|
||||
|
||||
## `include` queries
|
||||
Getting related models is easy, just use a query parameter `include`.
|
||||
|
||||
```js
|
||||
// returns all teams with their related City model
|
||||
// GET /teams?include=city or
|
||||
// GET /teams?include={"include": {"model": "City"}}}
|
||||
// GET /teams?include={"model": "City"}
|
||||
|
||||
|
||||
// results in a Sequelize query:
|
||||
@ -126,7 +138,7 @@ Team.findAll({include: [Player]})
|
||||
Filtering by related models property, you can pass **where** paremeter inside each **include** item(s) object.
|
||||
```js
|
||||
// returns all team with their related City where City property name equals Healdsburg
|
||||
// GET /teams?include={"include": {"model": "City", "where": {"name": "Healdsburg"}}}
|
||||
// GET /teams?include={"model": "City", "where": {"name": "Healdsburg"}}
|
||||
|
||||
// results in a Sequelize query:
|
||||
Team.findAll({include: {model: City, where: {name: 'Healdsburg'}}})
|
||||
|
Reference in New Issue
Block a user