enhancement on #588

This commit is contained in:
mamboer 2015-05-14 09:55:54 +08:00
parent ba68df3ef3
commit 5ff3798e8e
2 changed files with 22 additions and 10 deletions

View File

@ -162,15 +162,12 @@ function defineScope(cls, targetClass, name, params, methods, options) {
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;
['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 = {

View File

@ -729,12 +729,27 @@ describe('relations', function () {
});
});
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');
done();
//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();
});
});
});
}
});