Browse Source

Merge branch 'master-issue7591' of https://github.com/chinpei215/cakephp into issue7591

Jose Lorenzo Rodriguez 10 years ago
parent
commit
1f4a42867b
1 changed files with 21 additions and 0 deletions
  1. 21 0
      tests/TestCase/ORM/QueryRegressionTest.php

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

@@ -944,6 +944,27 @@ class QueryRegressionTest extends TestCase
     }
 
     /**
+     * Tests calling contain in a nested closure
+     *
+     * @see https://github.com/cakephp/cakephp/issues/7591
+     * @return void
+     */
+    public function testContainInNestedClosure()
+    {
+        $table = TableRegistry::get('Comments');
+        $table->belongsTo('Articles');
+        $table->Articles->belongsTo('Authors');
+        $table->Articles->Authors->belongsToMany('Tags');
+
+        $query = $table->find()->where(['Comments.id' => 5])->contain(['Articles' => function ($q) {
+            return $q->contain(['Authors' => function ($q) {
+                return $q->contain('Tags');
+            }]);
+        }]);
+        $this->assertCount(2, $query->first()->article->author->tags);
+    }
+
+    /**
      * Test that the typemaps used in function expressions
      * create the correct results.
      *