Merge branch 'patch-4' of github.com:lchenay/loopback-datasource-juggler into lchenay-patch-4
This commit is contained in:
commit
6239d8fde5
10
lib/scope.js
10
lib/scope.js
|
@ -248,9 +248,15 @@ function mergeQuery(base, update) {
|
|||
}
|
||||
}
|
||||
|
||||
// Overwrite inclusion
|
||||
// Merge inclusion
|
||||
if (update.include) {
|
||||
base.include = update.include;
|
||||
if (!base.include) {
|
||||
base.include = update.include;
|
||||
} else {
|
||||
var saved = base.include;
|
||||
base.include = {};
|
||||
base.include[update.include] = [saved];
|
||||
}
|
||||
}
|
||||
if (update.collect) {
|
||||
base.collect = update.collect;
|
||||
|
|
|
@ -276,6 +276,34 @@ describe('relations', function () {
|
|||
}
|
||||
});
|
||||
|
||||
it('should allow to use include syntax on related data', function (done) {
|
||||
var Address = db.define('Address', {name: String});
|
||||
Patient.belongsTo(Address);
|
||||
Physician.create(function (err, physician) {
|
||||
physician.patients.create({name: 'a'}, function (err, patient) {
|
||||
Address.create({name: 'z'}, function (err, address) {
|
||||
patient.address(address);
|
||||
patient.save(function() {
|
||||
verify(physician);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
function verify(physician) {
|
||||
physician.patients({include: 'address'}, function (err, ch) {
|
||||
should.not.exist(err);
|
||||
should.exist(ch);
|
||||
ch.should.have.lengthOf(1);
|
||||
ch[0].addressId.should.equal(1);
|
||||
var address = ch[0].address();
|
||||
should.exist(address);
|
||||
address.should.be.an.instanceof(Address);
|
||||
address.name.should.equal('z');
|
||||
done();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it('should set targetClass on scope property', function() {
|
||||
should.equal(Physician.prototype.patients._targetClass, 'Patient');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue