diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 1cb8c6460214..c12ee855918b 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -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 @@ -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; } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 3d99909d0aa3..bcc86aa5fda3 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -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)