I’m having problems with the Timestampable functionality in Doctrine 1.2.2 and 1.2.3.
The error I get on trying to save() my Record is:
Uncaught exception ‘Doctrine_Validator_Exception’ with message ‘Validation failed in class XXX 1 field had validation error: * 1 validator failed on created_at (unsigned) ‘ in …
I’ve created the relevant field in the MySQL table as:
created_atDATETIME NOT NULL,
Then in setTableDefinition() I have:
$this->hasColumn('created_at', 'timestamp', null, array( 'type' => 'timestamp', 'fixed' => false, 'unsigned' => false, 'primary' => false, 'notnull' => true, 'autoincrement' => false, ));
Which is taken straight from the output of generateModelsFromDb().
And finally my setUp() looks like:
public function setUp() { parent::setUp(); $this->actAs('Timestampable', array( 'created' => array( 'name' => 'created_at', 'type' => 'timestamp', 'format' => 'Y-m-d H:i:s', 'disabled' => false, 'options' => array() ), 'updated' => array( 'disabled' => true ))); }
(I’ve tried not defining all of those fields for ‘created’, but I get the same problem.)
I’m a bit stumped as to what I’m doing wrong – for one thing I can’t see why Doctrine would be running any unsigned checks against a ‘timestamp’ datatype…
Updated
I’m on Debian Lenny (5.0.8) with MySQL (5.0.51a-24+lenny5O). The problem is occurring with Doctrine 1.2.3 and 1.2.2. I noticed that Doctrine’s examples use TIMESTAMP MySQL columns rather than DATETIMEs, so I changed that and re-generated, but the problem still recurred. I also thought it might be a problem with the MySQL definition, so I ran generateSqlFromModels to get the right SQL, but that was fine too (DATETIME NOT NULL).
I’m totally stumped – have logged a bug in Doctrine JIRA to see if I can get this figured out: DC-965
Any help gratefully received!
Alex
Yesss solved on my case!
And hopefully on your case as well!
When I started the project I worked on, I wanted by default all my columns to be:
which you can set in yml config files in symfony or with plain php like:
$manager->setAttribute(Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS, array(‘notnull’ => true, ‘unsigned’ => true));
And of course unsigned attribute DOES NOT get applied in the database for string columns right?
Which made me assume Doctrine wouldn’t care either about it… WRONG
When you activate Validators: http://www.doctrine-project.org/projects/orm/1.2/docs/manual/component-overview/pl#validator, Doctrine tries to validate that string column, or timestamp/datime column with an unsigned validator!
On my case removing that default column attribute solved it. And if you haven’t set defaults then maybe you should set unsigned as False using that method and then do it per column in your model definition where you need it.