Skip to content

Commit

Permalink
Adding a test case to prove #4454
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 1, 2014
1 parent 001ec16 commit cb6c095
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/TestCase/ORM/QueryRegressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,35 @@ public function testPluginAssociationQueryGeneration() {
);
}

/**
* Tests that loading associations having the same alias in the
* joinable associations chain is not sensitive to the order in which
* the associations are selected.
*
* @see https://github.com/cakephp/cakephp/issues/4454
* @return void
*/
public function testAssociationChainOrder() {
$articles = TableRegistry::get('Articles');
$articles->belongsTo('Authors');
$articles->hasOne('ArticlesTags');

$articlesTags = TableRegistry::get('ArticlesTags');
$articlesTags->belongsTo('Authors', [
'foreignKey' => 'tag_id'
]);

$resultA = $articles->find()
->contain(['ArticlesTags.Authors', 'Authors'])
->first();

$resultB = $articles->find()
->contain(['Authors', 'ArticlesTags.Authors'])
->first();

$this->assertEquals($resultA, $resultB);
$this->assertNotEmpty($resultA->user);
$this->assertNotEmpty($resultA->articles_tag->user);
}

}

0 comments on commit cb6c095

Please sign in to comment.