From 4506a69236446543ea6fe5fa4186175c1b9ecf83 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Thu, 12 Dec 2013 10:43:16 +0000 Subject: [PATCH] Idiorm issue #156 findMany() returns only the last record in a set --- README.markdown | 6 ++++++ paris.php | 21 +++++++++------------ test/ParisTest.php | 6 ------ test/idiorm.php | 23 +++-------------------- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/README.markdown b/README.markdown index 599937e4..64c90900 100644 --- a/README.markdown +++ b/README.markdown @@ -72,6 +72,12 @@ foreach ($tweets as $tweet) { Changelog --------- +#### 1.4.2 - released 2013-12-12 + +**Patch update to remove a broken pull request** - may have consequences for users of 1.4.0 and 1.4.1 that exploited the "`find_many()` now returns an associative array with the databases primary ID as the array keys" change that was merged in 1.4.0. + +* Back out pull request/issue [#133](https://github.com/j4mie/idiorm/pull/133) as it breaks backwards compatibility in previously unexpected ways (see Idiorm issues [#162](https://github.com/j4mie/idiorm/pull/162), [#156](https://github.com/j4mie/idiorm/issues/156) and [#133](https://github.com/j4mie/idiorm/pull/133#issuecomment-29063108)) - sorry for merging this change into Paris - closes Idiorm [issue 156](https://github.com/j4mie/idiorm/issues/156) + #### 1.4.1 - released 2013-09-05 * Increment composer.json requirement for Idiorm to 1.4.0 [[michaelward82](https://github.com/michaelward82)] - [Issue #72](https://github.com/j4mie/paris/pull/72) diff --git a/paris.php b/paris.php index e766d38c..4441ce1a 100644 --- a/paris.php +++ b/paris.php @@ -119,19 +119,16 @@ public function find_one($id=null) { } /** - * 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 function _instances_with_id_as_key($rows) { - $instances = array(); - foreach($rows as $row) { - $row = $this->_create_model_instance($this->_create_instance_from_row($row)); - $instances[$row->id()] = $row; + * Wrap Idiorm's find_many method to return + * an array of instances of the class associated + * with this wrapper instead of the raw ORM class. + */ + public function find_many() { + $results = parent::find_many(); + foreach($results as $key => $result) { + $results[$key] = $this->_create_model_instance($result); } - return $instances; + return $results; } /** diff --git a/test/ParisTest.php b/test/ParisTest.php index 0d03edfd..3b9475e3 100644 --- a/test/ParisTest.php +++ b/test/ParisTest.php @@ -192,10 +192,4 @@ public function testHasManyThroughRelationWithCustomIntermediateModelAndKeyNames $this->assertEquals($expected, ORM::get_last_query()); } - public function testFindResultSet() { - $result_set = Model::factory('BookFive')->find_result_set(); - $this->assertInstanceOf('IdiormResultSet', $result_set); - $this->assertSame(count($result_set), 5); - } - } \ No newline at end of file diff --git a/test/idiorm.php b/test/idiorm.php index dd5cea20..d37e9f94 100644 --- a/test/idiorm.php +++ b/test/idiorm.php @@ -611,23 +611,7 @@ public function find_many() { */ protected function _find_many() { $rows = $this->_run(); - 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 function _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; + return array_map(array($this, '_create_instance_from_row'), $rows); } /** @@ -1673,7 +1657,7 @@ public function id() { * database when save() is called. */ public function set($key, $value = null) { - return $this->_set_orm_property($key, $value); + $this->_set_orm_property($key, $value); } /** @@ -1686,7 +1670,7 @@ public function set($key, $value = null) { * @param string|null $value */ public function set_expr($key, $value = null) { - return $this->_set_orm_property($key, $value, true); + $this->_set_orm_property($key, $value, true); } /** @@ -1708,7 +1692,6 @@ protected function _set_orm_property($key, $value = null, $expr = false) { $this->_expr_fields[$field] = true; } } - return $this; } /**