|
|
@@ -374,4 +374,35 @@ class QueryRegressionTest extends TestCase {
|
|
|
);
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|