Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Document auto update/create columns. #70

merged 1 commit into from

2 participants


I thought I'd make another attempt at documenting these properties as they're not very intuitive. This is related to issue 3938

@kemo kemo merged commit ece5244 into kohana:3.2/develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 4 deletions.
  1. +7 −4 classes/kohana/orm.php
  2. +19 −0 guide/orm/
11 classes/kohana/orm.php
@@ -139,14 +139,17 @@ public static function factory($model, $id = NULL)
protected $_table_columns;
- * Auto-update columns for updates
- * @var string
+ * Auto-update column name & format for updates.
+ * @see $_created_column
+ * @var mixed An `array` with 'column' and 'format' keys and values or NULL for no auto update column
protected $_updated_column = NULL;
- * Auto-update columns for creation
- * @var string
+ * Auto-update column name & format for creation. If 'format' is TRUE, the
+ * php 'time()' method will be used, otherwise the 'format' will be passed
+ * as the format parameter to the php 'date()' function.
+ * @var mixed An `array` with 'column' and 'format' keys and values or NULL for no auto update column
protected $_created_column = NULL;
19 guide/orm/
@@ -26,3 +26,22 @@ ORM assumes each model (and database table) has an `id` column that is indexed a
For each model, you can define which database configuration ORM will run queries on. If you override the `$_db_group` variable in your model, ORM will connect to that database. Example:
protected $_db_group = 'alternate';
+## Auto-update columns
+If you'd like date/time columns automatically updated whenever your model is
+changed or created you can define the `$_created_column` and/or
+`$_updated_column` properties in your model. Use an `array` with 'column'
+and 'format' keys & values, where 'column' is the column name to be updated
+and 'format' is the date format to use. You can set 'format' to TRUE
+for a Unix timestamp, or specify a string format like that expected for the
+php `date()` function.
+The following example will automatically update the 'last_changed' column
+with the current Unix timestamp whenever the model is updated:
+ class Model_Member extends ORM
+ {
+ protected $_updated_column = array('column' => 'last_changed',
+ 'format' => TRUE);
+ }
Something went wrong with that request. Please try again.