Browse Source

Initial fix for conflict between contain and matching.

Currently it only works for MySQL
Jose Lorenzo Rodriguez 11 years ago
parent
commit
3e8f150903
2 changed files with 20 additions and 2 deletions
  1. 1 1
      src/ORM/EagerLoader.php
  2. 19 1
      tests/TestCase/ORM/QueryRegressionTest.php

+ 1 - 1
src/ORM/EagerLoader.php

@@ -435,7 +435,7 @@ class EagerLoader
             return;
         }
 
-        $config['strategy'] = Association::STRATEGY_SELECT;
+        $config['strategy'] = Association::STRATEGY_SUBQUERY;
         $loadable->config($config);
         $loadable->canBeJoined(false);
     }

+ 19 - 1
tests/TestCase/ORM/QueryRegressionTest.php

@@ -727,7 +727,6 @@ class QueryRegressionTest extends TestCase
         $this->assertNotNull($result->article->author);
     }
 
-
     /**
      * Tests that trying to contain an inexistent association
      * throws an exception and not a fatal error.
@@ -740,4 +739,23 @@ class QueryRegressionTest extends TestCase
         $comments = TableRegistry::get('Comments');
         $comments->find()->contain('Deprs')->all();
     }
+
+    public function testFindMatchingWithContain()
+    {
+        $comments = TableRegistry::get('Comments');
+        $comments->belongsTo('Articles');
+        $comments->belongsTo('Users');
+
+        $result = $comments->find()
+            ->contain(['Articles', 'Users'])
+            ->matching('Articles', function ($q) {
+                return $q->where(['Articles.id >=' => 1]);
+            })
+            ->matching('Users', function ($q) {
+                return $q->where(['Users.id >=' => 1]);
+            })
+            ->first();
+        $this->assertInstanceOf('Cake\ORM\Entity', $result->article);
+        $this->assertInstanceOf('Cake\ORM\Entity', $result->user);
+    }
 }