Skip to content

Commit

Permalink
Revert "Make find(list) not auto-null on a behavior of 2.x"
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Feb 23, 2016
1 parent d8e3ced commit 6e3b38d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
18 changes: 0 additions & 18 deletions src/ORM/Table.php
Expand Up @@ -1017,24 +1017,6 @@ public function findAll(Query $query, array $options)
*/
public function findList(Query $query, array $options)
{
if (!isset($options['keyField']) && !isset($options['valueField'])) {
$select = $query->clause('select');
if ($select && count($select) <= 2) {
$keyField = array_shift($select);

$valueField = array_shift($select) ?: $keyField;
list($model, $keyField) = pluginSplit($keyField);
if (!$model || $model === $this->alias()) {
$options['keyField'] = $keyField;
}

list($model, $valueField) = pluginSplit($valueField);
if (!$model || $model === $this->alias()) {
$options['valueField'] = $valueField;
}
}
}

$options += [
'keyField' => $this->primaryKey(),
'valueField' => $this->displayField(),
Expand Down
37 changes: 0 additions & 37 deletions tests/TestCase/ORM/TableTest.php
Expand Up @@ -1249,43 +1249,6 @@ public function testFindListSelectedFields()
$this->assertSame($expected, $query->toArray());
}

/**
* Test that find('list') also works as it used to in 2.x.
*
* @return void
*/
public function testFindListAutoSelectedFields()
{
$Users = new Table([
'table' => 'users',
'alias' => 'Users',
'connection' => $this->connection,
]);
$Users->displayField('username');

$query = $Users->find('list', ['fields' => ['id', 'created']]);
$expected = ['id', 'created'];
$this->assertSame($expected, $query->clause('select'));

$query = $Users->find('list', ['fields' => ['id']]);
$expected = ['id'];
$this->assertSame($expected, $query->clause('select'));
$expected = [
1 => 1,
2 => 2,
3 => 3,
4 => 4
];
$this->assertSame($expected, $query->toArray());

$query = $Users->find('list', ['fields' => ['Users.id', 'Users.created']]);
$expected = ['Users.id', 'Users.created'];
$this->assertSame($expected, $query->clause('select'));

$results = $query->toArray();
$this->assertInstanceOf('Cake\I18n\Time', array_shift($results));
}

/**
* test that find('list') does not auto add fields to select if using virtual properties
*
Expand Down

0 comments on commit 6e3b38d

Please sign in to comment.