diff options
author | Simon Holywell <[email protected]> | 2012-11-12 13:18:47 +0000 |
---|---|---|
committer | Simon Holywell <[email protected]> | 2012-11-12 13:18:54 +0000 |
commit | 004bfacb21b529f252b2cc22c6c84445280d38ff (patch) | |
tree | 23a376bbebe6882fee3efd7b06ca764855ccf037 /README.markdown | |
parent | b8795513004394dac0c9162fe05fb6b5ee4093d9 (diff) |
Add set_expr() closing issues #43 & #59
Diffstat (limited to 'README.markdown')
-rw-r--r-- | README.markdown | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index d5a2933..51b5b74 100644 --- a/README.markdown +++ b/README.markdown @@ -36,6 +36,7 @@ Changelog * Add `select_many` and `select_many_expr` - closing issues #49 and #69 * Add support for `MIN`, `AVG`, `MAX` and `SUM` - closes issue #16 * Add `group_by_expr` - closes issue #24 +* Add `set_expr` to allow database expressions to be set as ORM properties - closes issues #59 and #43 [[brianherbert](https://github.com/brianherbert)] #### 1.1.1 - release 2011-01-30 @@ -414,6 +415,18 @@ To update the database, change one or more of the properties of the object, then // Syncronise the object with the database $person->save(); +#### Properties containing expressions #### + +It is possible to set properties on the model that contain database expressions using the `set_expr` method. + + $person = ORM::for_table('person')->find_one(5);; + $person->set('name', 'Bob Smith'); + $person->age = 20; + $person->set_expr('updated', 'NOW()'); + $person->save(); + +The `updated` column's value will be inserted into query in its raw form therefore allowing the database to execute any functions referenced - such as `NOW()` in this case. + ### Creating new records ### To add a new record, you need to first create an "empty" object instance. You then set values on the object as normal, and save it. @@ -427,6 +440,18 @@ To add a new record, you need to first create an "empty" object instance. You th After the object has been saved, you can call its `id()` method to find the autogenerated primary key value that the database assigned to it. +#### Properties containing expressions #### + +It is possible to set properties on the model that contain database expressions using the `set_expr` method. + + $person = ORM::for_table('person')->create(); + $person->set('name', 'Bob Smith'); + $person->age = 20; + $person->set_expr('added', 'NOW()'); + $person->save(); + +The `added` column's value will be inserted into query in its raw form therefore allowing the database to execute any functions referenced - such as `NOW()` in this case. + ### Checking whether a property has been modified ### To check whether a property has been changed since the object was created (or last saved), call the `is_dirty` method: |