开发者

Doctrine unsigned validation error storing created_at

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 crea开发者_JAVA百科ted_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...

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:

notnull: true
unsigned: true

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.


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.


You're definition should follow this: (this from Yaml)

created_atn:
  type: timestamp(25)
  fixed: false
  unsigned: false
  primary: false
  notnull: false
  autoincrement: false


I have added the following code into the Base directory and respective file. And my issue gor solved.. thx

  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
                                      )));
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜