Skip to content

Commit dd1a875

Browse files
committed
Merge pull request #80 from j4mie/develop
Idiorm issue #156 findMany() returns only the last record in a set
2 parents b60d085 + 4506a69 commit dd1a875

4 files changed

Lines changed: 18 additions & 38 deletions

File tree

README.markdown

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ foreach ($tweets as $tweet) {
7272
Changelog
7373
---------
7474

75+
#### 1.4.2 - released 2013-12-12
76+
77+
**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.
78+
79+
* 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)
80+
7581
#### 1.4.1 - released 2013-09-05
7682

7783
* Increment composer.json requirement for Idiorm to 1.4.0 [[michaelward82](https://github.com/michaelward82)] - [Issue #72](https://github.com/j4mie/paris/pull/72)

paris.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,16 @@ public function find_one($id=null) {
119119
}
120120

121121
/**
122-
* Create instances of each row in the result and map
123-
* them to an associative array with the primary IDs as
124-
* the array keys.
125-
* @param array $rows
126-
* @return array
127-
*/
128-
protected function _instances_with_id_as_key($rows) {
129-
$instances = array();
130-
foreach($rows as $row) {
131-
$row = $this->_create_model_instance($this->_create_instance_from_row($row));
132-
$instances[$row->id()] = $row;
122+
* Wrap Idiorm's find_many method to return
123+
* an array of instances of the class associated
124+
* with this wrapper instead of the raw ORM class.
125+
*/
126+
public function find_many() {
127+
$results = parent::find_many();
128+
foreach($results as $key => $result) {
129+
$results[$key] = $this->_create_model_instance($result);
133130
}
134-
return $instances;
131+
return $results;
135132
}
136133

137134
/**

test/ParisTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,4 @@ public function testHasManyThroughRelationWithCustomIntermediateModelAndKeyNames
192192
$this->assertEquals($expected, ORM::get_last_query());
193193
}
194194

195-
public function testFindResultSet() {
196-
$result_set = Model::factory('BookFive')->find_result_set();
197-
$this->assertInstanceOf('IdiormResultSet', $result_set);
198-
$this->assertSame(count($result_set), 5);
199-
}
200-
201195
}

test/idiorm.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -611,23 +611,7 @@ public function find_many() {
611611
*/
612612
protected function _find_many() {
613613
$rows = $this->_run();
614-
return $this->_instances_with_id_as_key($rows);
615-
}
616-
617-
/**
618-
* Create instances of each row in the result and map
619-
* them to an associative array with the primary IDs as
620-
* the array keys.
621-
* @param array $rows
622-
* @return array
623-
*/
624-
protected function _instances_with_id_as_key($rows) {
625-
$instances = array();
626-
foreach($rows as $row) {
627-
$row = $this->_create_instance_from_row($row);
628-
$instances[$row->id()] = $row;
629-
}
630-
return $instances;
614+
return array_map(array($this, '_create_instance_from_row'), $rows);
631615
}
632616

633617
/**
@@ -1673,7 +1657,7 @@ public function id() {
16731657
* database when save() is called.
16741658
*/
16751659
public function set($key, $value = null) {
1676-
return $this->_set_orm_property($key, $value);
1660+
$this->_set_orm_property($key, $value);
16771661
}
16781662

16791663
/**
@@ -1686,7 +1670,7 @@ public function set($key, $value = null) {
16861670
* @param string|null $value
16871671
*/
16881672
public function set_expr($key, $value = null) {
1689-
return $this->_set_orm_property($key, $value, true);
1673+
$this->_set_orm_property($key, $value, true);
16901674
}
16911675

16921676
/**
@@ -1708,7 +1692,6 @@ protected function _set_orm_property($key, $value = null, $expr = false) {
17081692
$this->_expr_fields[$field] = true;
17091693
}
17101694
}
1711-
return $this;
17121695
}
17131696

17141697
/**

0 commit comments

Comments
 (0)