Skip to content

Commit f865ee4

Browse files
matej21dg
authored andcommitted
Selection::fetchAssoc fix
1 parent 4b38d79 commit f865ee4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Database/Table/Selection.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ public function fetchAll()
265265
*/
266266
public function fetchAssoc($path)
267267
{
268-
return Nette\Utils\Arrays::associate($this->fetchAll(), $path);
268+
$rows = array_map('iterator_to_array', $this->fetchAll());
269+
return Nette\Utils\Arrays::associate($rows, $path);
269270
}
270271

271272

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Database\Table: Fetch assoc.
5+
*
6+
* @dataProvider? ../databases.ini
7+
*/
8+
9+
use Tester\Assert;
10+
11+
require __DIR__ . '/../connect.inc.php'; // create $connection
12+
13+
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");
14+
15+
16+
test(function() use ($context) {
17+
$apps = $context->table('book')->order('title')->fetchAssoc('id=title'); // SELECT * FROM `book` ORDER BY `title`
18+
Assert::same(array(
19+
1 => '1001 tipu a triku pro PHP',
20+
4 => 'Dibi',
21+
2 => 'JUSH',
22+
3 => 'Nette',
23+
), $apps);
24+
});

0 commit comments

Comments
 (0)