Skip to content
Permalink
Browse files

Revert "Make find(list) not auto-null on a behavior of 2.x"

  • Loading branch information...
markstory committed Feb 23, 2016
1 parent d8e3ced commit 6e3b38ddd140d885b8ae1a03169c70178f500e62
Showing with 0 additions and 55 deletions.
  1. +0 −18 src/ORM/Table.php
  2. +0 −37 tests/TestCase/ORM/TableTest.php
@@ -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(),
@@ -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
*

0 comments on commit 6e3b38d

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