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:
Muhammad Labib Ramadhan
2016-11-07 08:48:52 +07:00
parent 1977304287
commit 11306667d6
4 changed files with 59 additions and 57 deletions

View File

@ -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'}}})