Skip to content
Permalink
Browse files

Fix invalid SQL generation from leftJoinWith() & auto-fields

When no fields are selected, and auto-fields is enabled, `$fields` gets
set to false which ends up as '' in SQL causing invalid field lists.

Refs #11663
  • Loading branch information...
markstory committed Jan 27, 2018
1 parent c0231dc commit 0f8dd73970e5b3641ea041ab9d64d2b8f85568a0
Showing with 21 additions and 1 deletion.
  1. +2 −1 src/ORM/Association.php
  2. +19 −0 tests/TestCase/ORM/QueryTest.php
@@ -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) {
@@ -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()
*

0 comments on commit 0f8dd73

Please sign in to comment.
You can’t perform that action at this time.