-
Notifications
You must be signed in to change notification settings - Fork 0
DSL: Select
joelwatson edited this page May 19, 2015
·
1 revision
CriteriaBuilder allows you produce result sets that limit the data of the current store via the DSL.
To add an individual column, you can use the column() method:
cb.column({propertyName}, {propertyAlias}); cb.column('firstName', 'myFirstName');
You can optionally include an alias as the second argument to transform the name of the field.
If a property you want to include in the result set is from an association of the store's model, you should include the join alias when defining the column inclusion:
cb.column('a.address', 'addy'); // can be chained cb.column('firstName').column('a.address').(...)
NOTE: When using a "select" statement, only "store" and "collection" return results will be affected.
If you know before-hand precisely which columns you'd like to include, you can also use the columns() method to conveniently add them all at once:
// as array of arrays cb.columns([['orderNumber'],['u.firstName', 'first']]) // as array of objects cb.columns([ { name:'orderNumber' }, { name:'u.firstName', alias:'first' } ]);
var cb = new CriteriaBuilder.Builder({ store: mystore }); // add columns cb.columns([['orderNumber'],['u.firstName', 'first']]) // run cb.query({type:'collection'});