Skip to content
Permalink
Browse files

Fixes #6214

  • Loading branch information...
lorenzo committed Mar 30, 2015
1 parent db34583 commit 06335950c489815acc30992f46ada06a3caac003
Showing with 25 additions and 0 deletions.
  1. +5 −0 src/ORM/ResultSet.php
  2. +20 −0 tests/TestCase/ORM/QueryRegressionTest.php
@@ -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])) {
@@ -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.
You can’t perform that action at this time.