Browse Source

Tests that it is possible to count results containing hasMany
associations both hydrating and not hydrating the results.

Ber Clausen 12 years ago
parent
commit
b53df001a0
1 changed files with 31 additions and 0 deletions
  1. 31 0
      tests/TestCase/ORM/QueryTest.php

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

@@ -239,6 +239,37 @@ class QueryTest extends TestCase {
 	}
 
 /**
+ * Tests that it is possible to count results containing hasMany associations
+ * both hydrating and not hydrating the results.
+ *
+ * @dataProvider strategiesProvider
+ * @return void
+ */
+	public function testHasManyEagerLoadingCount($strategy) {
+		$table = TableRegistry::get('authors');
+		TableRegistry::get('articles');
+		$table->hasMany('articles', [
+			'property' => 'articles',
+			'strategy' => $strategy,
+			'sort' => ['articles.id' => 'asc']
+		]);
+		$query = new Query($this->connection, $table);
+
+		$query = $query->select()
+			->contain('articles');
+
+		$expected = 4;
+
+		$results = $query->hydrate(false)
+			->count();
+		$this->assertEquals($expected, $results);
+
+		$results = $query->hydrate(true)
+			->count();
+		$this->assertEquals($expected, $results);
+	}
+
+/**
  * Tests that it is possible to set fields & order in a hasMany result set
  *
  * @dataProvider strategiesProvider