Browse Source

Adding a test case to prove #4454

Jose Lorenzo Rodriguez 11 years ago
parent
commit
cb6c095723
1 changed files with 31 additions and 0 deletions
  1. 31 0
      tests/TestCase/ORM/QueryRegressionTest.php

+ 31 - 0
tests/TestCase/ORM/QueryRegressionTest.php

@@ -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);
+	}
+
 }