summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Wiesenthal <[email protected]>2013-08-30 10:46:27 +0100
committerSimon Holywell <[email protected]>2013-08-30 10:46:27 +0100
commit022d328fcd82755d07b702f07a1fb03e348278bf (patch)
treeae3e953d738076e464e3fe0959e79bd50f823150
parentbd82ffdc63883ca24b85ad01e2a60491d6bb48a4 (diff)
Issue #133 find_many returns an associative array
-rw-r--r--idiorm.php18
1 files changed, 17 insertions, 1 deletions
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;
}
/**