Allow include syntax without scope param

This commit is contained in:
Fabien Franzen 2014-10-10 17:17:36 +02:00
parent 771d9505cc
commit 8d6e3adaab
2 changed files with 12 additions and 1 deletions

View File

@ -15,7 +15,7 @@ function normalizeInclude(include) {
// Build an array of key/value pairs // Build an array of key/value pairs
var newInclude = []; var newInclude = [];
var rel = include.rel || include.relation; var rel = include.rel || include.relation;
if (typeof rel === 'string' && isPlainObject(include.scope)) { if (typeof rel === 'string') {
var obj = {}; var obj = {};
obj[rel] = new IncludeScope(include.scope); obj[rel] = new IncludeScope(include.scope);
newInclude.push(obj); newInclude.push(obj);

View File

@ -79,6 +79,17 @@ describe('include', function () {
done(); done();
}); });
}); });
it('should fetch Passport - Owner - Posts - alternate syntax', function (done) {
Passport.find({include: {owner: {relation: 'posts'}}}, function (err, passports) {
should.not.exist(err);
should.exist(passports);
passports.length.should.be.ok;
var posts = passports[0].owner().posts();
posts.should.have.length(3);
done();
});
});
it('should fetch Passports - User - Posts - User', function (done) { it('should fetch Passports - User - Posts - User', function (done) {
Passport.find({ Passport.find({