Skip to content

Commit

Permalink
Merge pull request #80 from j4mie/develop
Browse files Browse the repository at this point in the history
Idiorm issue #156 findMany() returns only the last record in a set
  • Loading branch information
treffynnon committed Dec 12, 2013
2 parents b60d085 + 4506a69 commit dd1a875
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
6 changes: 6 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions paris.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
6 changes: 0 additions & 6 deletions test/ParisTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
23 changes: 3 additions & 20 deletions test/idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -1708,7 +1692,6 @@ protected function _set_orm_property($key, $value = null, $expr = false) {
$this->_expr_fields[$field] = true;
}
}
return $this;
}

/**
Expand Down

0 comments on commit dd1a875

Please sign in to comment.