Skip to content

Commit

Permalink
Add test covering correct use for #10592
Browse files Browse the repository at this point in the history
Aliased fields must include the association names or the ORM cannot
correctly map the result set onto entities.
  • Loading branch information
markstory committed Apr 28, 2017
1 parent 0450ecc commit edfb0c6
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Expand Up @@ -91,6 +91,32 @@ public function testEagerLoadingFromEmptyResults()
$this->assertEmpty($results);
}

/**
* Tests that eagerloading associations with aliased fields works.
*
* @return void
*/
public function testEagerLoadingAliasedAssociationFields()
{
$this->loadFixtures('Articles', 'Authors');
$table = TableRegistry::get('Articles');
$table->belongsTo('Authors', [
'foreignKey' => 'author_id'
]);
$result = $table->find()
->contain(['Authors' => [
'fields' => [
'id',
'Authors__aliased_name' => 'name'
]
]])
->where(['Articles.id' => 1])
->first();
$this->assertInstanceOf(EntityInterface::class, $result);
$this->assertInstanceOf(EntityInterface::class, $result->author);
$this->assertSame('mariano', $result->author->aliased_name);
}

/**
* Tests that eagerloading and hydration works for associations that have
* different aliases in the association and targetTable
Expand Down

0 comments on commit edfb0c6

Please sign in to comment.