Browse Source

Adding test to prove that using contain and matchin on the same assoc works

Jose Lorenzo Rodriguez 11 years ago
parent
commit
6f8c3bde16
1 changed files with 25 additions and 0 deletions
  1. 25 0
      tests/TestCase/ORM/QueryTest.php

+ 25 - 0
tests/TestCase/ORM/QueryTest.php

@@ -2280,4 +2280,29 @@ class QueryTest extends TestCase {
 		$this->assertNull($articles[2]->author);
 	}
 
+/**
+ * Tests that it is possible to call matching and contain on the same
+ * association.
+ *
+ * @return void
+ */
+	public function testMatchingWithContain() {
+		$query = new Query($this->connection, $this->table);
+		$table = TableRegistry::get('authors');
+		$table->hasMany('articles');
+		TableRegistry::get('articles')->belongsToMany('tags');
+
+		$result = $query->repository($table)
+			->select()
+			->matching('articles.tags', function ($q) {
+				return $q->where(['tags.id' => 2]);
+			})
+			->contain('articles')
+			->first();
+
+		$this->assertEquals(1, $result->id);
+		$this->assertCount(2, $result->articles);
+		$this->assertEquals(2, $result->_matchingData['tags']->id);
+	}
+
 }