Optional
If an array: a list of the attributes that you want to select. Attributes can also be raw SQL (literal), fn, col, and cast
literal
fn
col
cast
To rename an attribute, you can pass an array, with two elements:
If include is used: selects all the attributes of the model, plus some additional ones. Useful for aggregations.
include
{ attributes: { include: [[literal('COUNT(id)'), 'total']] } Copy
{ attributes: { include: [[literal('COUNT(id)'), 'total']] }
If exclude is used: selects all the attributes of the model, except the one specified in exclude. Useful for security purposes
exclude
{ attributes: { exclude: ['password'] } } Copy
{ attributes: { exclude: ['password'] } }
If an array: a list of the attributes that you want to select. Attributes can also be raw SQL (
literal
),fn
,col
, andcast
To rename an attribute, you can pass an array, with two elements:
literal
,fn
,col
,cast
),If
include
is used: selects all the attributes of the model, plus some additional ones. Useful for aggregations.