diff --git a/test/relations.test.js b/test/relations.test.js index a39a3fdc8..3f42832f1 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -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();