diff --git a/src/Database/Table/Selection.php b/src/Database/Table/Selection.php index 9a70758fd..3cb5fc387 100644 --- a/src/Database/Table/Selection.php +++ b/src/Database/Table/Selection.php @@ -265,7 +265,8 @@ public function fetchAll() */ public function fetchAssoc($path) { - return Nette\Utils\Arrays::associate($this->fetchAll(), $path); + $rows = array_map('iterator_to_array', $this->fetchAll()); + return Nette\Utils\Arrays::associate($rows, $path); } diff --git a/tests/Database/Table/Selection.fetchAssoc().phpt b/tests/Database/Table/Selection.fetchAssoc().phpt new file mode 100644 index 000000000..fde021ca7 --- /dev/null +++ b/tests/Database/Table/Selection.fetchAssoc().phpt @@ -0,0 +1,24 @@ +table('book')->order('title')->fetchAssoc('id=title'); // SELECT * FROM `book` ORDER BY `title` + Assert::same(array( + 1 => '1001 tipu a triku pro PHP', + 4 => 'Dibi', + 2 => 'JUSH', + 3 => 'Nette', + ), $apps); +});