From 288781c034c5b33ffb408471238cf58eff7674fb Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Sun, 26 Jun 2016 14:38:14 +0200 Subject: [PATCH] Making test more clear and re-adding missing junction conditions in subquery for `notMatching` --- src/ORM/Association/BelongsToMany.php | 3 ++- tests/TestCase/ORM/QueryTest.php | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/ORM/Association/BelongsToMany.php b/src/ORM/Association/BelongsToMany.php index cac4d5d8faa..ee4554fbed7 100644 --- a/src/ORM/Association/BelongsToMany.php +++ b/src/ORM/Association/BelongsToMany.php @@ -378,7 +378,8 @@ protected function _appendNotMatching($query, $options) $subquery = $this->find() ->select(array_values($conds)) - ->where($options['conditions']); + ->where($options['conditions']) + ->andWhere($this->junctionConditions()); $subquery = $options['queryBuilder']($subquery); diff --git a/tests/TestCase/ORM/QueryTest.php b/tests/TestCase/ORM/QueryTest.php index 7f8993003d3..67c1955ac38 100644 --- a/tests/TestCase/ORM/QueryTest.php +++ b/tests/TestCase/ORM/QueryTest.php @@ -2995,7 +2995,8 @@ public function testLeftJoinWithNested() ->find() ->select([ 'authors.id', - 'total_articles' => 'count(tags.id)']) + 'tagged_articles' => 'count(tags.id)' + ]) ->leftJoinWith('articles.tags', function ($q) { return $q->where(['tags.name' => 'tag3']); }) @@ -3007,7 +3008,7 @@ public function testLeftJoinWithNested() 3 => 1, 4 => 0 ]; - $this->assertEquals($expected, $results->combine('id', 'total_articles')->toArray()); + $this->assertEquals($expected, $results->combine('id', 'tagged_articles')->toArray()); } /**