js-data-sql
js-data-sql copied to clipboard
Enhancements to "with"
Just logging some notes to think about at this point
Retrieve a subset of properties
- asked by aaike on Slack#i-need-help
var users = yield Event.findAll({...}, {
with: [
// load all comments, what we currently support
'comments',
// load only comments with category_id = 1 (shorthand for '==')
{comments: {category_id: 1}},
// load only comments with category_id > 1
{comments: {category_id: {'>': 1}}}
]
});
Support for adding calculated/aggregate properties
- discussed in Slack#js-data-sql
var events = yield Event.findAll({...}, {
with: [
// add `review_count` property to each event
{review_count: {'review.rating': 'count'}},
// add `review_average` property to each event
{review_average: {'review.rating': 'average'}},
]
});