summaryrefslogtreecommitdiff
path: root/README.markdown
diff options
context:
space:
mode:
authorJamie Matthews <[email protected]>2010-11-01 23:18:03 +0000
committerJamie Matthews <[email protected]>2010-11-01 23:18:03 +0000
commite86cd738287a8e36ed1ecbcb9197fa22b851f271 (patch)
treee36fd7071a64284d1deab77c421dc713fe9f9108 /README.markdown
parent518fee9a9b32ce7a8effc348b99d8f82690abe58 (diff)
Add as_array method to return raw data wrapped by ORM instances
Diffstat (limited to 'README.markdown')
-rw-r--r--README.markdown16
1 files changed, 16 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown
index f4ed43f..1144a43 100644
--- a/README.markdown
+++ b/README.markdown
@@ -263,6 +263,22 @@ Once you've got a set of records (objects) back from a query, you can access pro
$name = $person->get('name');
$name = $person->name;
+You can also get the all the data wrapped by an ORM instance using the `as_array` method. This will return an associative array mapping column names (keys) to their values.
+
+The `as_array` method takes column names as optional arguments. If one or more of these arguments is supplied, only matching column names will be returned.
+
+ $person = ORM::for_table('person')->create();
+
+ $person->first_name = 'Fred';
+ $person->surname = 'Bloggs';
+ $person->age = 50;
+
+ // Returns array('first_name' => 'Fred', 'surname' => 'Bloggs', 'age' => 50)
+ $data = $person->as_array();
+
+ // Returns array('first_name' => 'Fred', 'age' => 50)
+ $data = $person->as_array('first_name', 'age');
+
### Updating records ###
To update the database, change one or more of the properties of the object, then call the `save` method to commit the changes to the database. Again, you can change the values of the object's properties either by using the `set` method or by setting the value of the property directly: