Skip to content

Commit 327d188

Browse files
authored
Docs update about top-level where and nested column syntax (feathersjs-ecosystem#372)
1 parent 4eb6c33 commit 327d188

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

README.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ __Options:__
8282
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size
8383
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`)
8484
- `operators` (*optional*) - A mapping from query syntax property names to to [Sequelize secure operators](http://docs.sequelizejs.com/manual/tutorial/querying.html)
85-
- `whitelist` (*optional*) - A list of additional query parameters to allow (e..g `[ '$regex', '$geoNear' ]`). Default is the supported `operators`
85+
- <span id="options-whitelist">`whitelist`</span> (*optional*) - A list of additional query parameters to allow (e..g `[ '$regex', '$geoNear' ]`). Default is the supported `operators`
8686

8787
### params.sequelize
8888

@@ -106,9 +106,13 @@ app.service('messages').hooks({
106106
});
107107
```
108108

109+
Other options that `params.sequelize` allows you to pass can be found in [Sequelize querying docs](https://sequelize.org/master/manual/model-querying-basics.html).
110+
Beware that when setting a [top-level `where` property](https://sequelize.org/master/manual/eager-loading.html#complex-where-clauses-at-the-top-level) (usually for querying based on a column on an associated model), the `where` in `params.sequelize` will overwrite your `query`.
111+
112+
109113
### operators
110114

111-
Sequelize deprecated string based operators a while ago for security reasons. Starting at version 4.0.0 `feathers-sequelize` converts queries securely. If you want to support additional Sequelize operators, the `operators` service option can contain a mapping from query parameter name to Sequelize operator. By default supported are:
115+
Sequelize deprecated string based operators a while ago for security reasons. Starting at version 4.0.0 `feathers-sequelize` converts queries securely, so you can still use string based operators listed below. If you want to support additional Sequelize operators, the `operators` service option can contain a mapping from query parameter name to Sequelize operator. By default supported are:
112116

113117
```
114118
'$eq',
@@ -302,6 +306,25 @@ Additionally to the [common querying mechanism](https://docs.feathersjs.com/api/
302306

303307
> **Note**: This adapter supports an additional `$returning` parameter for patch and remove queries. By setting `params.$returning = false` it will disable feathers and sequelize from returning what was changed, so mass updates can be done without overwhelming node and/or clients.
304308
309+
### Querying a nested column
310+
311+
To query based on a column in an associated model, you can use Sequelize's [nested column syntax](https://sequelize.org/master/manual/eager-loading.html#complex-where-clauses-at-the-top-level) in a query. The nested column syntax is considered an operator by Feathers, and so each such usage has to be [whitelisted](#options-whitelist).
312+
313+
Example:
314+
```js
315+
// Find a user with post.id == 120
316+
app.service('users').find({
317+
query: {
318+
'$user.post.id$': 120,
319+
include: {
320+
model: posts
321+
}
322+
}
323+
});
324+
```
325+
326+
For this case to work, you'll need to add '$user.post.id$' to the service options' ['whitelist' property](#options-whitelist).
327+
305328
## Working with Sequelize Model instances
306329

307330
It is highly recommended to use `raw` queries, which is the default. However, there are times when you will want to take advantage of [Sequelize Instance](http://docs.sequelizejs.com/en/latest/api/instance/) methods. There are two ways to tell feathers to return Sequelize instances:

0 commit comments

Comments
 (0)