Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1484,6 +1484,14 @@ public function lists($column, $key = null)
// otherwise we can just give these values back without a specific key.
$results = new Collection($this->get($columns));

// If the selected column contains a "dot", we will remove it so that the list
// operation can run normally. Specifying the table is not needed, since we
// really want the names of the columns as it is in this resulting array.
if (($dot = strpos($columns[0], '.')) !== false)
{
$columns[0] = substr($columns[0], $dot + 1);
}

$values = $results->fetch($columns[0])->all();

// If a key was specified and we have results, we will go ahead and combine
Expand All @@ -1510,14 +1518,6 @@ protected function getListSelect($column, $key)
{
$select = is_null($key) ? array($column) : array($column, $key);

// If the selected column contains a "dot", we will remove it so that the list
// operation can run normally. Specifying the table is not needed, since we
// really want the names of the columns as it is in this resulting array.
if (($dot = strpos($select[0], '.')) !== false)
{
$select[0] = substr($select[0], $dot + 1);
}

return $select;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,15 @@ public function testListMethodsGetsArrayOfColumnValues()
$results = $builder->from('users')->where('id', '=', 1)->lists('foo');
$this->assertEquals(array('bar', 'baz'), $results);

$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('select')->once()->with('select "users"."foo" from "users" where "id" = ?', array(1))->andReturn(array(array('foo' => 'bar'), array('foo' => 'baz')));
$builder->getProcessor()->shouldReceive('processSelect')->once()->with($builder, array(array('foo' => 'bar'), array('foo' => 'baz')))->andReturnUsing(function($query, $results)
{
return $results;
});
$results = $builder->from('users')->where('id', '=', 1)->lists('users.foo');
$this->assertEquals(array('bar', 'baz'), $results);

$builder = $this->getBuilder();
$builder->getConnection()->shouldReceive('select')->once()->andReturn(array(array('id' => 1, 'foo' => 'bar'), array('id' => 10, 'foo' => 'baz')));
$builder->getProcessor()->shouldReceive('processSelect')->once()->with($builder, array(array('id' => 1, 'foo' => 'bar'), array('id' => 10, 'foo' => 'baz')))->andReturnUsing(function($query, $results)
Expand Down