From 004bfacb21b529f252b2cc22c6c84445280d38ff Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Mon, 12 Nov 2012 13:18:47 +0000 Subject: Add set_expr() closing issues #43 & #59 --- README.markdown | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'README.markdown') 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: -- cgit v1.2.3