Permalink
Browse files

Tests that it is possible to count results containing hasMany

associations both hydrating and not hydrating the results.
  • Loading branch information...
1 parent ef1ea0a commit b53df001a0cd36e86f2da0e404670eb77e5f4f9c @bar bar committed Mar 6, 2014
Showing with 31 additions and 0 deletions.
  1. +31 −0 tests/TestCase/ORM/QueryTest.php
@@ -239,6 +239,37 @@ public function testHasManyEagerLoadingNoHydration($strategy) {
}
/**
+ * 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

0 comments on commit b53df00

Please sign in to comment.