From 022d328fcd82755d07b702f07a1fb03e348278bf Mon Sep 17 00:00:00 2001 From: Erik Wiesenthal Date: Fri, 30 Aug 2013 10:46:27 +0100 Subject: Issue #133 find_many returns an associative array --- idiorm.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/idiorm.php b/idiorm.php index a43c767..062ed7f 100644 --- a/idiorm.php +++ b/idiorm.php @@ -611,7 +611,23 @@ */ protected function _find_many() { $rows = $this->_run(); - return array_map(array($this, '_create_instance_from_row'), $rows); + return $this->_instances_with_id_as_key($rows); + } + + /** + * Create instances of each row in the result and map + * them to an associative array with the primary IDs as + * the array keys. + * @param array $rows + * @return array + */ + protected _instances_with_id_as_key($rows) { + $instances = array(); + foreach($rows as $row) { + $row = $this->_create_instance_from_row($row); + $instances[$row->id()] = $row; + } + return $instances; } /** -- cgit v1.2.3