Skip to content

Commit

Permalink
feat(orm): change isHidden docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Apr 18, 2024
1 parent a65c7ee commit 543892d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
16 changes: 15 additions & 1 deletion docs/orm/annotations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,27 @@ public id: number

> Default: `false`
Set if the column should be hidden when retrieving it from database:
Set if the field should be hidden when executing the
`toJSON()` method of the model:

```typescript
@Column({ isHidden: true })
public password: string
```

:::tip

To force return hidden fields in `toJSON()` calls,
use the `withHidden` option:

```typescript
const flight = await Flight.find()

const flightJson = flight.toJSON({ withHidden: true })
```

:::

### `isUnique`

> Default: `false`
Expand Down
22 changes: 7 additions & 15 deletions docs/orm/query-builder.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ You may use any of these methods when writing your model queries.

:::

### Hiding fields
### Hidding fields

Sometimes you might need to hide some sensitive field from your model
queries, to do so, you can set the `isHidden` property to true in your
Expand All @@ -75,29 +75,21 @@ export class User extends BaseModel {
}
```

Everytime you call the `query()` method of your models, Athenna will
automatically select all the columns from your model but never the
ones where the `isHidden` property is true.
Everytime you call the `toJSON()` method of your models, Athenna will
ignore all the hidden columns from your model and return the rest.

#### Retrieve hidden fields

Is possible to bypass the `isHidden` validation using the
`select()` method from the query builder:
`withHidden` option of the `toJSON()` method:

```typescript
const { password } = await User.query()
const user = await User.query()
.select('id')
.select('password') 👈
.select('password')
.find()
```

If you wish to get all the hidden fields for a specify use case, you
can use the `withHidden()` method:

```typescript
const { password } = await User.query()
.withHidden()
.find()
const { password } = user.toJSON({ withHidden: true }) 👈
```

## Collections
Expand Down

0 comments on commit 543892d

Please sign in to comment.