Skip to content

Commit

Permalink
Issue #17 Add find_array method
Browse files Browse the repository at this point in the history
  • Loading branch information
treffynnon committed Nov 12, 2012
1 parent 3208bca commit 3c082ca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Changelog
* Prevent ambiguous column names when joining tables - issue #66 [[hellogerard](https://github.com/hellogerard)]
* Add `delete_many` method [[CBeerta](https://github.com/CBeerta)]
* Allow unsetting of ORM parameters [[CBeerta](https://github.com/CBeerta)]
* Add `find_array` to get the records as associative arrays [[Surt](https://github.com/Surt)] - closes issue #17

#### 1.1.1 - release 2011-01-30

Expand Down Expand Up @@ -129,6 +130,14 @@ To find all records where the `gender` is `female`:

$females = ORM::for_table('person')->where('gender', 'female')->find_many();

##### As an associative array #####

You can also find many records as an associative array instead of Idiorm instances. To do this substitute any call to `find_many()` with `find_array()`.

$females = ORM::for_table('person')->where('gender', 'female')->find_array();

This is useful if you need to serialise the the query output into a format like JSON and you do not need the ability to update the returned records.

#### Counting results ####

To return a count of the number of rows that would be returned by a query, call the `count()` method.
Expand Down
10 changes: 10 additions & 0 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,16 @@ public function find_many() {
return array_map(array($this, '_create_instance_from_row'), $rows);
}

/**
* Tell the ORM that you are expecting multiple results
* from your query, and execute it. Will return an array,
* or an empty array if no rows were returned.
* @return array
*/
public function find_array() {
return $this->_run();
}

/**
* Tell the ORM that you wish to execute a COUNT query.
* Will return an integer representing the number of
Expand Down

0 comments on commit 3c082ca

Please sign in to comment.