Skip to content

Commit

Permalink
Add warning when user attempts to query on an assn with a limit claus…
Browse files Browse the repository at this point in the history
…e, issue #215
  • Loading branch information
Ben Ng committed Jul 25, 2014
1 parent 1d6332c commit d10b815
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/query/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Query.prototype = new (function () {
// Walks through the associations and updates modelName
// until we reach the property name
if (keyName.indexOf('.') > -1) {
if(self.opts != null && self.opts.limit != null) {
throw new Error('It is not possible to query on an association when there is a limit clause')
}

keyNameArr = keyName.split('.');

while(keyNameArr.length > 1) {
Expand Down Expand Up @@ -205,6 +209,10 @@ Query.prototype = new (function () {
// Walks through the associations and updates modelName
// until we reach the property name
if (keyName.indexOf('.') > -1) {
if(this.opts != null && this.opts.limit != null) {
throw new Error('It is not possible to query on an association when there is a limit clause')
}

keyNameArr = keyName.split('.');
modelName = this.model.modelName;

Expand Down
22 changes: 22 additions & 0 deletions test/integration/adapters/sql/eager_assn.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ tests = {
);
}

, 'test includes, querying on an association with a limit clause throws the proper error': function () {
assert.throws(
function () {
model.Person.all({'friends.id': 1}, { includes: 'friends', limit: 1 }, function () {

});
},
/It\sis\snot\spossible\sto\squery\son\san\sassociation\swhen\sthere\sis\sa\slimit\sclause/
);
}

, 'test includes, querying on an association with an implicit limit clause throws the proper error': function () {
assert.throws(
function () {
model.Person.first({'friends.id': 1}, { includes: 'friends' }, function () {

});
},
/It\sis\snot\spossible\sto\squery\son\san\sassociation\swhen\sthere\sis\sa\slimit\sclause/
);
}

, 'test named, reflexive, hasMany/through with properties on the join-model': function (next) {
model.Person.all({}, {sort: 'title'}, function (err, data) {
if (err) { throw err; }
Expand Down

0 comments on commit d10b815

Please sign in to comment.