Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests that it is possible to count results containing hasMany

associations both hydrating and not hydrating the results.
  • Loading branch information...
commit b53df001a0cd36e86f2da0e404670eb77e5f4f9c 1 parent ef1ea0a
Ber Clausen bar authored
Showing with 31 additions and 0 deletions.
  1. +31 −0 tests/TestCase/ORM/QueryTest.php
31 tests/TestCase/ORM/QueryTest.php
View
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.