Commit 536c4fd5 authored by gnat's avatar gnat

optional fields

parent 542f9b0d
......@@ -58,12 +58,16 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener
*/
public function preInsert(Doctrine_Event $event)
{
if(!$this->_options['created']['disabled']) {
$createdName = $this->_options['created']['name'];
$updatedName = $this->_options['updated']['name'];
$event->getInvoker()->$createdName = $this->getTimestamp('created');
}
if(!$this->_options['updated']['disabled']) {
$updatedName = $this->_options['updated']['name'];
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
}
}
/**
* preUpdate
......@@ -73,10 +77,11 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener
*/
public function preUpdate(Doctrine_Event $event)
{
if(!$this->_options['updated']['disabled']) {
$updatedName = $this->_options['updated']['name'];
$event->getInvoker()->$updatedName = $this->getTimestamp('updated');
}
}
/**
* getTimestamp
......
......@@ -42,10 +42,12 @@ class Doctrine_Template_Timestampable extends Doctrine_Template
protected $_options = array('created' => array('name' => 'created_at',
'type' => 'timestamp',
'format' => 'Y-m-d H:i:s',
'disabled' => false,
'options' => array()),
'updated' => array('name' => 'updated_at',
'type' => 'timestamp',
'format' => 'Y-m-d H:i:s',
'disabled' => false,
'options' => array()));
/**
......@@ -66,9 +68,12 @@ class Doctrine_Template_Timestampable extends Doctrine_Template
*/
public function setTableDefinition()
{
if(!$this->_options['created']['disabled']) {
$this->hasColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']);
}
if(!$this->_options['updated']['disabled']) {
$this->hasColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']);
}
$this->addListener(new Doctrine_Template_Listener_Timestampable($this->_options));
}
}
......@@ -273,10 +273,12 @@ class User extends Doctrine_Record
$this->actAs('Timestampable', array('created' => array('name' => 'created_at',
'type' => 'timestamp',
'format' => 'Y-m-d H:i:s',
'disabled' => false,
'options' => array()),
'updated' => array('name' => 'updated_at',
'type' => 'timestamp',
'format' => 'Y-m-d H:i:s',
'disabled' => false,
'options' => array())));
}
}
......@@ -305,6 +307,28 @@ User:
type: string(255)
</code>
If you are only interested in keeping using only one of the columns, such as a created_at timestamp, but not a an updated_at field, set the flag disabled=>true for either of the fields as in the example below.
YAML Example
<code type="yaml">
---
User:
actAs:
Timestampable:
created:
name: created_at
type: timestamp
format:Y-m-d H:i:s
options: []
updated:
disabled: true
columns:
username:
type: string(125)
password:
type: string(255)
</code>
+++ Sluggable
If you do not specify the columns to create the slug from, it will default to just using the toString() method on the model.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment