views:

196

answers:

1

Hi, I'm having problems with the Timestampable functionality in Doctrine 1.2.2.

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_at DATETIME 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...

Any help gratefully received!

Alex

A: 

Umm... not totally sure about the Doctrine specifics of this, but as you point out, DATETIME/TIMESTAMP doesn't deal with the attribute UNSIGNED, as it's not a numeric type.

I would start by removing the UNSIGNED declaration from your table definition.

Hope that helps.

Tom
Thanks for the suggestion - I've tried removing the UNSIGNED declaration, and then the UNSIGNED and FIXED, from the table definition but no luck.
Alex Dean
Hmm... something else I spotted: why's there a NULL length declared in the $this->hasColumn([name], [type], [length], [options])? Just an idea but maybe try removing the NULL, or possibly declaring a correct length for a DATETIME field (8?).
Tom
Null is the length you should use for dates and datetimes in Doctrine apparently. I've tried 19 but no change.Also I tried simplifying the Timestampable to $this->actAs('Timestampable') - then I got "2 fields had validation errors: * 1 validator failed on created_at (unsigned) * 1 validator failed on updated_at (unsigned)". (The table didn't have an updated_at field). Maybe this suggests that it's not a specific issue with an unsigned check, but rather with Doctrine not finding the columns?
Alex Dean