Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include merge options in chain find count #386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/ChainFind.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ function ChainFind(Model, opts) {
return this;
},
count: function (cb) {
opts.driver.count(opts.table, opts.conditions, {}, function (err, data) {
opts.driver.count(opts.table, opts.conditions, {
merge: opts.merge
}, function (err, data) {
if (err || data.length === 0) {
return cb(err);
}
Expand Down
29 changes: 29 additions & 0 deletions test/integration/model-find-chain.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,35 @@ describe("Model.find() chaining", function() {
return done();
});
});

// TODO: Make this code Mongo compatible?
// it("should account for associations", function (done) {
// var Bob = new Person({
// name: "Bob",
// surname: "Smith",
// age: 20
// });
// var Jill = new Person({
// name: "Jill",
// surname: "Smith",
// age: 20
// });

// Person.find({ name: "John" }, function (err, John) {
// should.equal(err, null);
// John = John[0];

// John.setParents([ Bob, Jill ], function (err) {
// should.equal(err, null);
// Person(John.id).getParents({ name: "Bob" }).count(function (err, count) {
// should.equal(err, null);
// count.should.equal(1);

// return done();
// });
// });
// });
// });
});

describe(".first()", function () {
Expand Down