Browse Source

Merge pull request #4391 from Laykou/patch-1

Remove autoFields from count method
José Lorenzo Rodríguez 11 years ago
parent
commit
632c555d3c
2 changed files with 17 additions and 0 deletions
  1. 1 0
      src/ORM/Query.php
  2. 16 0
      tests/TestCase/ORM/QueryTest.php

+ 1 - 0
src/ORM/Query.php

@@ -474,6 +474,7 @@ class Query extends DatabaseQuery implements JsonSerializable {
  */
 	public function count() {
 		$query = clone $this;
+		$query->autoFields(false);
 		$query->limit(null);
 		$query->order([], true);
 		$query->offset(null);

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

@@ -2073,4 +2073,20 @@ class QueryTest extends TestCase {
 		$this->assertArrayHasKey('compute', $result);
 	}
 
+/**
+ * Test that autofields works with count()
+ *
+ * @return void
+ */
+	public function testAutoFieldsCount() {
+		$table = TableRegistry::get('Articles');
+
+		$result = $table->find()
+			->select(['myField' => '(SELECT (2 + 2))'])
+			->autoFields(true)
+			->count();
+
+		$this->assertEquals(3, $result);
+	}
+
 }