Fields
Branden Horiuchi edited this page Nov 6, 2015
·
1 revision
The fields
method can be used to refine the fields to display. The method takes an array of fields that can be in dot notation and !notation. Fields in !notation will be the only fields excluded while fields without a ! prefix will be the only fields included
In the following example id
and name
will be the only fields returned in each record
pm(MyModel).forge()
.fields([`id`, `name`])
.paginate()
.end()
In the following example all fields except id
will be returned in each record
pm(MyModel).forge()
.fields([`!id`])
.paginate()
.end()
In the following example id
and group.id
will be returned from the model and a related model
pm(MyModel).forge()
.fields([`id`, `group.id`])
.paginate({
withRelated: ['group']
})
.end()