Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix query obj use for hasMany/through retrieval

  • Loading branch information...
commit 05dd51c2b1ed4dbef5325cc828261f482ab588b3 1 parent 39b2a89
@mde mde authored
Showing with 31 additions and 2 deletions.
  1. +9 −2 lib/association/index.js
  2. +22 −0 test/integration/adapters/shared.js
View
11 lib/association/index.js
@@ -51,6 +51,7 @@ association = new (function () {
, assnType = args.shift()
, callback = args.pop()
, query
+ , throughQuery
, opts
, otherKeyName
, selfKeyName
@@ -78,7 +79,13 @@ association = new (function () {
// Has query object
if (assnType == 'hasMany') {
- query = args.shift() || {};
+ if (through) {
+ query = {};
+ throughQuery = args.shift() || {};
+ }
+ else {
+ query = args.shift() || {};
+ }
}
// No query object, create one
else {
@@ -128,7 +135,7 @@ association = new (function () {
if (through) {
through = utils.string.getInflection(through, 'constructor', 'singular');
model[through][queryName](query, opts, function (err, data) {
- var query = {}
+ var query = throughQuery
, idColName
, idParam;
View
22 test/integration/adapters/shared.js
@@ -827,6 +827,28 @@ tests = {
});
}
+, 'test hasMany/through association lookup with query': function (next) {
+ model.Person.all(function (err, data) {
+ if (err) { throw err; }
+ var person = data[0];
+ model.Event.all(function (err, data) {
+ if (err) { throw err; }
+ var events = data;
+ events.forEach(function (ev) {
+ person.addEvent(ev);
+ });
+ person.save(function (err, data) {
+ if (err) { throw err; }
+ person.getEvents({title: 'a'}, function (err, data) {
+ if (err) { throw err; }
+ assert.equal(1, data.length);
+ next();
+ });
+ });
+ });
+ });
+ }
+
, 'test named hasMany/through association': function (next) {
model.Event.all(function (err, data) {
if (err) { throw err; }
Please sign in to comment.
Something went wrong with that request. Please try again.