Skip to content

Commit

Permalink
Merge pull request #61 from matej21/fix/selection_fetchAssoc
Browse files Browse the repository at this point in the history
Selection::fetchAssoc fix
  • Loading branch information
dg committed Apr 22, 2015
2 parents 0df4d5b + 9c0fc0c commit 78a0c89
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Database/Table/Selection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
24 changes: 24 additions & 0 deletions tests/Database/Table/Selection.fetchAssoc().phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

/**
* Test: Nette\Database\Table: Fetch assoc.
*
* @dataProvider? ../databases.ini
*/

use Tester\Assert;

require __DIR__ . '/../connect.inc.php'; // create $connection

Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../files/{$driverName}-nette_test1.sql");


test(function() use ($context) {
$apps = $context->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);
});

0 comments on commit 78a0c89

Please sign in to comment.