From 83a6e0020df14e294f888dd484c16fd989f5a5bc Mon Sep 17 00:00:00 2001 From: Vaclav Jares Date: Tue, 5 May 2015 14:15:10 +0200 Subject: [PATCH 1/2] Grouped selection - group fix --- src/Database/Table/GroupedSelection.php | 9 +++++++ .../Table/GroupedSelection.group.phpt | 27 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/Database/Table/GroupedSelection.group.phpt diff --git a/src/Database/Table/GroupedSelection.php b/src/Database/Table/GroupedSelection.php index e6ae366ba..710910795 100644 --- a/src/Database/Table/GroupedSelection.php +++ b/src/Database/Table/GroupedSelection.php @@ -85,6 +85,15 @@ public function order($columns) } + public function group($columns) + { + $this->emptyResultSet(); + $columns .= ", $this->name.$this->column"; + $this->sqlBuilder->setGroup($columns); + return $this; + } + + /********************* aggregations ****************d*g**/ diff --git a/tests/Database/Table/GroupedSelection.group.phpt b/tests/Database/Table/GroupedSelection.group.phpt new file mode 100644 index 000000000..403bb9633 --- /dev/null +++ b/tests/Database/Table/GroupedSelection.group.phpt @@ -0,0 +1,27 @@ + array(21, 22), + 2 => array(23), + 3 => array(21), + 4 => array(21, 22) + ); + $books = $context->table('book'); + foreach($books as $book){ + $pairs = $book->related('book_tag')->group('tag_id')->fetchPairs(NULL, 'tag_id'); + Assert::same($results[$book->id], array_values($pairs)); + } +}); From 7b94e4c6372c22e4897320de71f7525346132375 Mon Sep 17 00:00:00 2001 From: Vaclav Jares Date: Tue, 5 May 2015 14:34:29 +0200 Subject: [PATCH 2/2] GroupSelection.group.phpt - added sort to fix test for other database drivers --- tests/Database/Table/GroupedSelection.group.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Database/Table/GroupedSelection.group.phpt b/tests/Database/Table/GroupedSelection.group.phpt index 403bb9633..91fc0c964 100644 --- a/tests/Database/Table/GroupedSelection.group.phpt +++ b/tests/Database/Table/GroupedSelection.group.phpt @@ -21,7 +21,7 @@ test(function() use ($context) { ); $books = $context->table('book'); foreach($books as $book){ - $pairs = $book->related('book_tag')->group('tag_id')->fetchPairs(NULL, 'tag_id'); + $pairs = $book->related('book_tag')->group('tag_id')->order('tag_id')->fetchPairs(NULL, 'tag_id'); Assert::same($results[$book->id], array_values($pairs)); } });