Skip to content

Commit

Permalink
Fixing issue mentioned in #51 with query function
Browse files Browse the repository at this point in the history
Should use call rather than apply, test included
  • Loading branch information
tgriesser committed Aug 22, 2013
1 parent dd51ce2 commit bbc6994
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bookshelf.js
Expand Up @@ -58,7 +58,7 @@
if (args.length === 0) return this._builder;
var method = args[0];
if (_.isFunction(method)) {
method.apply(this._builder, this._builder);
method.call(this._builder, this._builder);
} else if (_.isObject(method)) {
for (var key in method) {
var target = _.isArray(method[key]) ? method[key] : [method[key]];
Expand Down
17 changes: 17 additions & 0 deletions test/lib/model.js
Expand Up @@ -127,6 +127,23 @@ module.exports = function(Bookshelf, handler) {
equal(qb.wheres.length, 2);
});

it('allows passing an function to query', function() {
var qb = model.resetQuery().query();
equal(qb.wheres.length, 0);
var q = model.query(function(qb) {
this.where({id: 1}).orWhere('id', '>', '10');
});
equal(q, model);
equal(qb.wheres.length, 2);
qb = model.resetQuery().query();
equal(qb.wheres.length, 0);
q = model.query(function(qb) {
qb.where({id: 1}).orWhere('id', '>', '10');
});
equal(q, model);
equal(qb.wheres.length, 2);
});


});

Expand Down

0 comments on commit bbc6994

Please sign in to comment.