Skip to content

Commit

Permalink
Add documentation for select and omit
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Bradshaw committed Mar 3, 2022
1 parent 06ce9cf commit 1cb5b5a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/concepts/ORM/Querylanguage.md
Expand Up @@ -235,10 +235,30 @@ _For performance reasons, case-sensitivity of `endsWith` depends on the database
Query options allow you refine the results that are returned from a query. They are used
in conjunction with a `where` key. The current options available are:

* `select`
* `omit`
* `limit`
* `skip`
* `sort`

#### Select

Chooses which attributes to return from a query. Note that `id` is always
returned, even if not included in the `select` list.

```usage
Model.find({ select: ['name'] })
```

#### Omit

Chooses which attributes to omit from a query. All attributes except for the
given attributes will be returned.

```usage
Model.find({ omit: ['middleName'] })
```

#### Limit

Limits the number of results returned from a query.
Expand Down
30 changes: 30 additions & 0 deletions docs/reference/waterline/queries/omit.md
@@ -0,0 +1,30 @@
# `.omit()`

Indicate which attributes to omit from the query. All attributes except for the
given attributes will be returned.

```usage
.omit(numRecordsToSkip)
```


### Usage

| | Argument | Type | Details |
|---|:------------------|-----------|------------|
| 1 | attributesToOmit | ((array)) | The names of fields to omit. |


### Example

To retrieve all attributes but `password` from the user named Rosa:

```javascript
var rosa = await User.findOne({ name: 'Rosa' })
.omit(['password'])

return res.json(rosa);
```

<docmeta name="displayName" value=".omit()">
<docmeta name="pageType" value="method">
30 changes: 30 additions & 0 deletions docs/reference/waterline/queries/select.md
@@ -0,0 +1,30 @@
# `.select()`

Indicate which attributes to select from the query. All attributes except for the
given attributes will be returned.

```usage
.select(attributesToInclude)
```


### Usage

| | Argument | Type | Details |
|---|:---------------------|-----------|------------|
| 1 | attributesToInclude | ((array)) | The names of fields to select. |


### Example

To retrieve only `name` from the user with id 1234

```javascript
var userInfo = await User.findOne({ id: 1234 })
.select(['name'])

return res.json(userInfo);
```

<docmeta name="displayName" value=".select()">
<docmeta name="pageType" value="method">

0 comments on commit 1cb5b5a

Please sign in to comment.