PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

include() enhancements #6

Closed PhilWaldmann closed 10 years ago

PhilWaldmann commented 10 years ago

Model.include() should support the following:

Model.include('$count').exec(function(records){
  console.log(records.$count);
});

or

Model.include('relation.$count').exec(function(records){
  console.log(records[0].relation.$count);
});

or just with a custom scope

Model.include('relation.my_scope').exec(function(records){

});

and with params

Model.include({'relation.$sum':'salary'}).exec(function(records){
  console.log(records[0].relation.$sum);
});

or with a single record

Model.find(1).include('$count').exec(function(record){
  console.log(record.$count);
});
PhilWaldmann commented 10 years ago

include() should just support

Model.include('relation.my_scope').exec(function(records){
});

and we need a additional method fetch to support count eager loading e.g.

Model.fetch('count').exec(function(result, fetchResult){
});

or

Model.fetch(Relation.where()).exec(function(result, fetchResult){
});
PhilWaldmann commented 10 years ago

first step is done with 0.17 More is comming with 1.0 - but it will break something

PhilWaldmann commented 10 years ago

we even get cross-store relations with the next release