Browse Source

Add test for #4804

Add a failing test for the associated loading failure.
Mark Story 11 years ago
parent
commit
f25b4155ec
1 changed files with 29 additions and 0 deletions
  1. 29 0
      tests/TestCase/ORM/QueryRegressionTest.php

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

@@ -473,4 +473,33 @@ class QueryRegressionTest extends TestCase {
 		$this->assertEquals(2, $count);
 	}
 
+/**
+ * Test that deep containments don't generate empty entities for
+ * intermediary relations.
+ *
+ * @return void
+ */
+	public function testContainNoEmptyAssociatedObjects() {
+		$comments = TableRegistry::get('Comments');
+		$comments->belongsTo('Users');
+		$users = TableRegistry::get('Users');
+		$users->hasMany('Articles', [
+			'foreignKey' => 'author_id'
+		]);
+
+		$comments->updateAll(['user_id' => 99], ['id' => 1]);
+
+		$result = $comments->find()
+			->contain(['Users'])
+			->where(['Comments.id' => 1])
+			->first();
+		$this->assertNull($result->user, 'No record should be null.');
+
+		$result = $comments->find()
+			->contain(['Users', 'Users.Articles'])
+			->where(['Comments.id' => 1])
+			->first();
+		$this->assertNull($result->user, 'No record should be null.');
+	}
+
 }