Skip to content

Commit

Permalink
Merge pull request #11666 from cakephp/issue-11663
Browse files Browse the repository at this point in the history
Fix invalid SQL generation from leftJoinWith() & auto-fields
  • Loading branch information
markstory committed Jan 28, 2018
2 parents c0231dc + 0f8dd73 commit 6e1db35
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ORM/Association.php
Expand Up @@ -1143,7 +1143,8 @@ protected function _appendFields($query, $surrogate, $options)
}

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) {
Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/ORM/QueryTest.php
Expand Up @@ -3317,6 +3317,25 @@ public function testLeftJoinWithSelect()
);
}

/**
* 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()
*
Expand Down

0 comments on commit 6e1db35

Please sign in to comment.