Browse Source

Added test provided by original reporter of #5463

Jose Lorenzo Rodriguez 11 years ago
parent
commit
be1af1ee8b
1 changed files with 20 additions and 0 deletions
  1. 20 0
      tests/TestCase/ORM/QueryRegressionTest.php

+ 20 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -595,4 +595,24 @@ class QueryRegressionTest extends TestCase {
 		$this->assertEquals($article->author, $article->_matchingData['Authors']);
 	}
 
+/**
+ * Checks that matching and contain can be called for the same belongsTo association
+ *
+ * @see https://github.com/cakephp/cakephp/issues/5463
+ * @return void
+ */
+	public function testFindMatchingAndContainWithSubquery() {
+		$table = TableRegistry::get('authors');
+		$table->hasMany('articles', ['strategy' => 'subquery']);
+		$table->articles->belongsToMany('tags');
+
+		$result = $table->find()
+			->matching('articles.tags', function ($q) {
+				return $q->where(['tags.id' => 2]);
+			})
+			->contain('articles');
+
+		$this->assertCount(2, $result->first()->articles);
+	}
+
 }