= Timestampable Behavior =

The `timestampable` behavior allows you to keep track of the date of creation and last update of your model objects.

== Basic Usage ==

In the `schema.xml`, use the `<behavior>` tag to add the `timestampable` behavior to a table:
{{{
#!xml
<table name="book">
  <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
  <column name="title" type="VARCHAR" required="true" primaryString="true" />
  <behavior name="timestampable" />
</table>
}}}

Rebuild your model, insert the table creation sql again, and you're ready to go. The model now has two new columns, `created_at` and `updated_at`, that store a timestamp automatically updated on save:

{{{
#!php
<?php
$b = new Book();
$b->setTitle('War And Peace');
$b->save();
echo $b->getCreatedAt(); // 2009-10-02 18:14:23
echo $b->getUpdatedAt(); // 2009-10-02 18:14:23
$b->setTitle('Anna Karenina');
$b->save();
echo $b->getCreatedAt(); // 2009-10-02 18:14:23
echo $b->getUpdatedAt(); // 2009-10-02 18:14:25
}}}

== Parameters ==

By default, the behavior adds two columns to the model. If these columns are already described in the schema, set the `add_columns` parameter to 'false', as follows:

{{{
#!xml
<table name="book">
  <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
  <column name="title" type="VARCHAR" required="true" primaryString="true" />
  <column name="created_at" type="TIMESTAMP" />
  <column name="updated_at" type="TIMESTAMP" />
  <behavior name="timestampable">
    <parameter name="add_columns" value="false" />
  </behavior>
</table>
}}}

You can also change the name of the columns by setting the `create_column` and `update_column` parameters:

{{{
#!xml
<table name="book">
  <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
  <column name="title" type="VARCHAR" required="true" primaryString="true" />
  <column name="my_create_date" type="TIMESTAMP" />
  <column name="my_update_date" type="TIMESTAMP" />
  <behavior name="timestampable">
    <parameter name="add_columns" value="false" />
    <parameter name="create_column" value="my_create_date" />
    <parameter name="update_column" value="my_update_date" />
  </behavior>
</table>
}}}

If you keep the `add_columns` parameter to 'true' by set custom column names, then the behavior will generate these columns:

{{{
#!xml
<table name="book">
  <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
  <column name="title" type="VARCHAR" required="true" primaryString="true" />
  <behavior name="timestampable">
    <parameter name="create_column" value="my_create_date" />
    <parameter name="update_column" value="my_update_date" />
  </behavior>
</table>
}}}

{{{
#!php
<?php
$b = new Book();
$b->setTitle('War And Peace');
$b->save();
echo $b->getMyCreateDate(); // 2009-10-02 18:14:23
echo $b->getMyUpdateDate(); // 2009-10-02 18:14:23
$b->setTitle('Anna Karenina');
$b->save();
echo $b->getMyCreateDate(); // 2009-10-02 18:14:23
echo $b->getMyUpdateDate(); // 2009-10-02 18:14:25
}}}
