commit
e0e6a0cdbb
|
@ -192,6 +192,13 @@ function defineScope(cls, targetClass, name, params, methods, options) {
|
|||
// see https://github.com/strongloop/loopback/issues/1076
|
||||
if (f._scope.collect &&
|
||||
condOrRefresh !== null && typeof condOrRefresh === 'object') {
|
||||
//extract the paging filters to the through model
|
||||
['limit','offset','skip','order'].forEach(function(pagerFilter){
|
||||
if(typeof(condOrRefresh[pagerFilter]) !== 'undefined'){
|
||||
f._scope[pagerFilter] = condOrRefresh[pagerFilter];
|
||||
delete condOrRefresh[pagerFilter];
|
||||
}
|
||||
});
|
||||
// Adjust the include so that the condition will be applied to
|
||||
// the target model
|
||||
f._scope.include = {
|
||||
|
|
|
@ -718,6 +718,42 @@ describe('relations', function () {
|
|||
}
|
||||
});
|
||||
|
||||
it('should fetch scoped instances with paging filters', function (done) {
|
||||
Physician.create(function (err, physician) {
|
||||
physician.patients.create({name: 'a'}, function () {
|
||||
physician.patients.create({name: 'z'}, function () {
|
||||
physician.patients.create({name: 'c'}, function () {
|
||||
verify(physician);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
function verify(physician) {
|
||||
//limit plus skip
|
||||
physician.patients({ limit:1, skip:1 },function (err, ch) {
|
||||
should.not.exist(err);
|
||||
should.exist(ch);
|
||||
ch.should.have.lengthOf(1);
|
||||
ch[0].name.should.eql('z');
|
||||
//offset plus skip
|
||||
physician.patients({ limit:1, offset:1 },function (err1, ch1) {
|
||||
should.not.exist(err1);
|
||||
should.exist(ch1);
|
||||
ch1.should.have.lengthOf(1);
|
||||
ch1[0].name.should.eql('z');
|
||||
//order
|
||||
physician.patients({ order: "patientId DESC" },function (err2, ch2) {
|
||||
should.not.exist(err2);
|
||||
should.exist(ch2);
|
||||
ch2.should.have.lengthOf(3);
|
||||
ch2[0].name.should.eql('c');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should find scoped record', function (done) {
|
||||
var id;
|
||||
Physician.create(function (err, physician) {
|
||||
|
|
Loading…
Reference in New Issue