Skip to content

Commit

Permalink
Fix loopbackio#1795 - Count issue with related models using though model
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Nov 30, 2019
1 parent f281d57 commit baf872f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/relations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,34 @@ describe('relations', function() {
db.automigrate(['Physician', 'Patient', 'Appointment', 'Address'], done);
});

it('should count scoped record with promises based on related model properties', function(done) {
let id;
Physician.create()
.then(function(physician) {
return physician.patients.create({name: 'a'})
.then(function(ch) {
id = ch.id;
return physician.patients.create({name: 'z'});
})
.then(function() {
return physician.patients.create({name: 'c'});
})
.then(function() {
return verify(physician);
});
}).catch(done);

function verify(physician) {
return physician.patients.count({
name: 'a',
}, function(err, count) {
if (err) return done(err);
count.should.equal(1);
done();
});
}
});

it('should build record on scope', function(done) {
Physician.create(function(err, physician) {
const patient = physician.patients.build();
Expand Down

0 comments on commit baf872f

Please sign in to comment.