js-data-sql icon indicating copy to clipboard operation
js-data-sql copied to clipboard

Enhancements to "with"

Open techniq opened this issue 8 years ago • 3 comments

Just logging some notes to think about at this point

Retrieve a subset of properties

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

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'}},
  ]
});

techniq avatar Feb 16 '16 04:02 techniq