Browse Source

Adding test to prove that matching() and contain() work for the same
association path

Jose Lorenzo Rodriguez 11 years ago
parent
commit
63546f794b
1 changed files with 23 additions and 0 deletions
  1. 23 0
      tests/TestCase/ORM/QueryTest.php

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

@@ -2285,4 +2285,27 @@ class QueryTest extends TestCase {
 		$this->assertEquals(2, $result->_matchingData['tags']->id);
 	}
 
+/**
+ * Tests that it is possible to call matching and contain on the same
+ * association with only onle level of depth.
+ *
+ * @return void
+ */
+	public function testNotSoFarMatchingWithContainOnTheSameAssociation() {
+		$table = TableRegistry::get('articles');
+		$table->belongsToMany('tags');
+
+		$result = $table
+			->find()
+			->matching('tags', function ($q) {
+				return $q->where(['tags.id' => 2]);
+			})
+				->contain('tags')
+				->first();
+
+		$this->assertEquals(1, $result->id);
+		$this->assertCount(2, $result->tags);
+		$this->assertEquals(2, $result->_matchingData['tags']->id);
+	}
+
 }