Skip to content

Commit

Permalink
Don't auto select fields if one of the options is a closure
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Apr 27, 2015
1 parent 5c910f0 commit 099e76c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/ORM/Table.php
Expand Up @@ -968,7 +968,11 @@ public function findList(Query $query, array $options)
trigger_error('Option "idField" is deprecated, use "keyField" instead.', E_USER_WARNING);
}

if (!$query->clause('select')) {
if (!$query->clause('select') &&
!is_object($options['keyField']) &&
!is_object($options['valueField']) &&
!is_object($options['groupField'])
) {
$fields = array_merge(
(array)$options['keyField'],
(array)$options['valueField'],
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -1197,6 +1197,11 @@ public function testFindListSelectedFields()
$expected = ['id', 'username'];
$this->assertSame($expected, $query->clause('select'));

$query = $table->find('list', ['valueField' => function ($row) {
return $row->username;
}]);
$this->assertEmpty($query->clause('select'));

$expected = ['odd' => new QueryExpression('id % 2'), 'id', 'username'];
$query = $table->find('list', [
'fields' => $expected,
Expand Down

0 comments on commit 099e76c

Please sign in to comment.