Criteria.prototype.select >= 1.1.0

Purpose

Select specific fields or associations

Syntax

Criteria#select ( Stringname );


Parameters

name
The name of the field or association to select

Examples

Select a single field

// Get an instance of the "Page" model
var Page = Model.get('Page');

// Calling "find" on that model without arguments returns a criteria
var criteria = Page.find();

// If we only want the "title" field, we can do so like this:
criteria.select('title');

// If we want multiple fields, like "title" and "body", we can use an array
criteria.select(['title', 'body']);

Select associations

// If the model has multiple associations, like "Comments", we can add those to the query
criteria.select('Comments');

// If we want to add multiple associations, we can use an array again
criteria.select(['Comments', 'Author']);

// And we can also select fields at the same time
criteria.select(['Comments', 'Author', 'title', 'body']);