Symfony 1.4 – Doctrine Timestampable Behaviour

Recently Symfony released their LTS 1.4 branch. Unlike previous versions Symfony 1.4 comes with Doctrine as default ORM.  If you have worked with Doctrine’s you will be familiar with its Timestampable behavior.

actAs:
  Timestampable: ~

Timestampable behavior  automatically adds a created_at and updated_at column and automatically set the values when a record is inserted and updated.  I mostly use Symfony Admin Generator to generate Backend. This behavior worked fined till Symfony 1.2, but in Symfony 1.3 / 1.4 for unknown reasons this behavior adds created_at and updated_at fields as required and their value must be filled during creation of new record in admin generator.

To fix this issue open your formClass located at

lib/form/doctrine/yourClassForm.Class.php

replace yourClass with actuall class name :) and add following code in configure function.

public function configure()
{
  //Following code will remove Required validators from these fields.
  unset($this->validatorSchema['created_at']);
  unset($this->validatorSchema['updated_at']);

  //following code will remove fields from form
  unset($this->widgetSchema['created_at']);
  unset($this->widgetSchema['updated_at']);
}

Hope this help

Similar Posts

7 Responses to “Symfony 1.4 – Doctrine Timestampable Behaviour”

rdcklinux on February 13th, 2010 at 1:52 AM

si ejecutas
unset($this['created_at'],$this['updated_at']);

hace exactamente lo mismo y es mas corto de escribir

rdcklinux on February 13th, 2010 at 1:54 AM

if you write
unset($this['created_at'],$this['updated_at']);
it is the same!!

rdcklinux on February 13th, 2010 at 1:56 AM

@rdcklinux
in symfony 1.4

Kryptic on February 13th, 2010 at 1:57 AM

@rdcklinux
Thanks for update :) but my code is more descriptive

Jorge on February 17th, 2010 at 11:52 PM

Y que sucede si lo que se desea es que aparezca el campo, por ejemplo el ID de una persona que es usado como llave primaria.

Hasta donde he visto Symfony lo oculta automaticamente…
cómo se debe configurar el Widget para que parezca?

Muchas gracias por su ayuda.

Kryptic on February 17th, 2010 at 11:59 PM

@Jorge
By admin por defecto de Symfony generados módulo muestra las claves principales. si no se muestran comprobar su archivo generator.yml
config:
list:
display: [id,name,etc]

Anton on April 25th, 2010 at 8:50 PM

Hi Stig!
Why you cant use more plain solution? Just pass “required => false” to these fields validators?

$this->validatorSchema['created_at']->setOption(‘required’, false);
$this->validatorSchema['updated_at']->setOption(‘required’, false);

Leave a Reply