Skip to content

Commit

Permalink
Fixes #6214
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Mar 30, 2015
1 parent db34583 commit 0633595
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/ORM/ResultSet.php
Expand Up @@ -527,6 +527,11 @@ protected function _groupResult($row)

foreach ($this->_containMap as $assoc) {
$alias = $assoc['nestKey'];

if ($assoc['canBeJoined'] && empty($this->_map[$alias])) {
continue;
}

$instance = $assoc['instance'];

if (!$assoc['canBeJoined'] && !isset($row[$alias])) {
Expand Down
20 changes: 20 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -798,4 +798,24 @@ public function testHasManyEagerLoadingUniqueKey()
->toArray();
$this->assertNotEmpty($result[0]->article);
}

/**
* Tests that using contain but selecting no fields from the association
* does not trigger any errors and fetches the right results.
*
* @see https://github.com/cakephp/cakephp/issues/6214
* @return void
*/
public function testContainWithNoFields()
{
$table = TableRegistry::get('Comments');
$table->belongsTo('Users');
$results = $table->find()
->select(['Comments.id', 'Comments.user_id'])
->contain(['Users'])
->where(['Users.id' => 1])
->combine('id', 'user_id');

$this->assertEquals([3 => 1, 4 => 1, 5 => 1], $results->toArray());
}
}

0 comments on commit 0633595

Please sign in to comment.