fix issue #587
This commit is contained in:
parent
eb7c29826c
commit
d27b2eb25f
10
lib/scope.js
10
lib/scope.js
|
@ -161,6 +161,16 @@ 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
|
||||
if( typeof(condOrRefresh.limit) !== 'undefined' ){
|
||||
f._scope.limit = condOrRefresh.limit;
|
||||
}
|
||||
if( typeof(condOrRefresh.skip) !== 'undefined' ){
|
||||
f._scope.skip = condOrRefresh.skip;
|
||||
}
|
||||
delete condOrRefresh.limit;
|
||||
delete condOrRefresh.skip;
|
||||
|
||||
// Adjust the include so that the condition will be applied to
|
||||
// the target model
|
||||
f._scope.include = {
|
||||
|
|
|
@ -718,6 +718,27 @@ 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) {
|
||||
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');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should find scoped record', function (done) {
|
||||
var id;
|
||||
Physician.create(function (err, physician) {
|
||||
|
|
Loading…
Reference in New Issue