diff --git a/lib/query/query.js b/lib/query/query.js index 3e1ef6d3..f8b8e82e 100644 --- a/lib/query/query.js +++ b/lib/query/query.js @@ -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) { @@ -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; diff --git a/test/integration/adapters/sql/eager_assn.js b/test/integration/adapters/sql/eager_assn.js index 14656ec2..ed65ed42 100644 --- a/test/integration/adapters/sql/eager_assn.js +++ b/test/integration/adapters/sql/eager_assn.js @@ -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; }