Skip to content

Commit baf872f

Browse files
committed
Fix loopbackio#1795 - Count issue with related models using though model
1 parent f281d57 commit baf872f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

test/relations.test.js

+28
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,34 @@ describe('relations', function() {
605605
db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], done);
606606
});
607607

608+
it('should count scoped record with promises based on related model properties', function(done) {
609+
let id;
610+
Physician.create()
611+
.then(function(physician) {
612+
return physician.patients.create({name: 'a'})
613+
.then(function(ch) {
614+
id = ch.id;
615+
return physician.patients.create({name: 'z'});
616+
})
617+
.then(function() {
618+
return physician.patients.create({name: 'c'});
619+
})
620+
.then(function() {
621+
return verify(physician);
622+
});
623+
}).catch(done);
624+
625+
function verify(physician) {
626+
return physician.patients.count({
627+
name: 'a',
628+
}, function(err, count) {
629+
if (err) return done(err);
630+
count.should.equal(1);
631+
done();
632+
});
633+
}
634+
});
635+
608636
it('should build record on scope', function(done) {
609637
Physician.create(function(err, physician) {
610638
const patient = physician.patients.build();

0 commit comments

Comments
 (0)