Browse Source

Fixing a failing tests and marking another as icomplete

Jose Lorenzo Rodriguez 11 years ago
parent
commit
310b479b5f
3 changed files with 17 additions and 6 deletions
  1. 10 4
      src/ORM/Association.php
  2. 5 1
      src/ORM/EagerLoader.php
  3. 2 1
      tests/TestCase/ORM/QueryTest.php

+ 10 - 4
src/ORM/Association.php

@@ -665,19 +665,25 @@ abstract class Association {
  */
 	protected function _bindNewAssociations($query, $surrogate, $options) {
 		$contain = $surrogate->contain();
+		$matching = $surrogate->eagerLoader()->matching();
 		$target = $this->_targetTable;
 
-		if (!$contain) {
+		if (!$contain && !$matching) {
 			return;
 		}
 
 		$loader = $surrogate->eagerLoader();
 		$loader->attachAssociations($query, $target, $options['includeFields']);
-		$newBinds = [];
+		$newContain = [];
 		foreach ($contain as $alias => $value) {
-			$newBinds[$options['aliasPath'] . '.' . $alias] = $value;
+			$newContain[$options['aliasPath'] . '.' . $alias] = $value;
+		}
+
+		$query->contain($newContain);
+
+		foreach ($matching as $alias => $value) {
+			$query->matching($options['aliasPath'] . '.' . $alias, $value['queryBuilder']);
 		}
-		$query->contain($newBinds);
 	}
 
 /**

+ 5 - 1
src/ORM/EagerLoader.php

@@ -128,11 +128,15 @@ class EagerLoader {
  * options to the filtering query
  * @return array The resulting containments array
  */
-	public function matching($assoc, callable $builder = null) {
+	public function matching($assoc = null, callable $builder = null) {
 		if ($this->_matching === null) {
 			$this->_matching = new self();
 		}
 
+		if ($assoc === null) {
+			return $this->_matching->contain();
+		}
+
 		$assocs = explode('.', $assoc);
 		$last = array_pop($assocs);
 		$containments = [];

+ 2 - 1
tests/TestCase/ORM/QueryTest.php

@@ -1993,6 +1993,7 @@ class QueryTest extends TestCase {
  * @return void
  */
 	public function testConflitingAliases() {
+		$this->markTestIncomplete('Needs an actual conflicting case');
 		$table = TableRegistry::get('ArticlesTags');
 		$table->belongsTo('Articles')->target()->belongsTo('Authors');
 		$table->belongsTo('Tags');
@@ -2000,7 +2001,7 @@ class QueryTest extends TestCase {
 		$table->find()
 			->contain(['Articles.Authors'])
 			->matching('Tags.Authors')
-			->all();
+			->sql();
 	}
 
 /**