Browse Source

Merge pull request #11666 from cakephp/issue-11663

Fix invalid SQL generation from leftJoinWith() & auto-fields
Mark Story 8 years ago
parent
commit
6e1db3599d
2 changed files with 21 additions and 1 deletions
  1. 2 1
      src/ORM/Association.php
  2. 19 0
      tests/TestCase/ORM/QueryTest.php

+ 2 - 1
src/ORM/Association.php

@@ -1143,7 +1143,8 @@ abstract class Association
         }
 
         if ($autoFields === true) {
-            $fields = array_merge((array)$fields, $target->getSchema()->columns());
+            $fields = array_filter((array)$fields);
+            $fields = array_merge($fields, $target->getSchema()->columns());
         }
 
         if ($fields) {

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

@@ -3318,6 +3318,25 @@ class QueryTest extends TestCase
     }
 
     /**
+     * Tests that leftJoinWith() can be used with autofields()
+     *
+     * @return void
+     */
+    public function testLeftJoinWithAutoFields()
+    {
+        $table = TableRegistry::get('articles');
+        $table->belongsTo('authors');
+
+        $results = $table
+            ->find()
+            ->leftJoinWith('authors', function ($q) {
+                return $q->enableAutoFields(true);
+            })
+            ->all();
+        $this->assertCount(3, $results);
+    }
+
+    /**
      * Tests innerJoinWith()
      *
      * @return void