diff --git a/lib/Doctrine/Template/Listener/Timestampable.php b/lib/Doctrine/Template/Listener/Timestampable.php index 232645abd..cbb96da3c 100644 --- a/lib/Doctrine/Template/Listener/Timestampable.php +++ b/lib/Doctrine/Template/Listener/Timestampable.php @@ -58,11 +58,15 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener */ public function preInsert(Doctrine_Event $event) { - $createdName = $this->_options['created']['name']; - $updatedName = $this->_options['updated']['name']; - - $event->getInvoker()->$createdName = $this->getTimestamp('created'); - $event->getInvoker()->$updatedName = $this->getTimestamp('updated'); + if(!$this->_options['created']['disabled']) { + $createdName = $this->_options['created']['name']; + $event->getInvoker()->$createdName = $this->getTimestamp('created'); + } + + if(!$this->_options['updated']['disabled']) { + $updatedName = $this->_options['updated']['name']; + $event->getInvoker()->$updatedName = $this->getTimestamp('updated'); + } } /** @@ -73,9 +77,10 @@ class Doctrine_Template_Listener_Timestampable extends Doctrine_Record_Listener */ public function preUpdate(Doctrine_Event $event) { - $updatedName = $this->_options['updated']['name']; - - $event->getInvoker()->$updatedName = $this->getTimestamp('updated'); + if(!$this->_options['updated']['disabled']) { + $updatedName = $this->_options['updated']['name']; + $event->getInvoker()->$updatedName = $this->getTimestamp('updated'); + } } /** diff --git a/lib/Doctrine/Template/Timestampable.php b/lib/Doctrine/Template/Timestampable.php index 2c1397852..904dd1486 100644 --- a/lib/Doctrine/Template/Timestampable.php +++ b/lib/Doctrine/Template/Timestampable.php @@ -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() { - $this->hasColumn($this->_options['created']['name'], $this->_options['created']['type'], null, $this->_options['created']['options']); - $this->hasColumn($this->_options['updated']['name'], $this->_options['updated']['type'], null, $this->_options['updated']['options']); - + 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)); } } diff --git a/manual/docs/en/class-templates.txt b/manual/docs/en/class-templates.txt index b3588c1e1..7c44b7d91 100644 --- a/manual/docs/en/class-templates.txt +++ b/manual/docs/en/class-templates.txt @@ -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) +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 + +--- +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) + + +++ 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.