views:

200

answers:

1

Hi there,

I have a schema.yml containing something similiar to the following:

Character:
  tableName: characters 
  actAs: { Timestampable: ~ }
  columns:
    id: { type: integer(4), primary: true, autoincrement: true }
    name: { type: string(255), notnull: true, notblank: true, minlength: 3 }

I define the minlength of the column name to be 3. I created a unit test to test the minlength validation, and I found out that the validation is not working.

$character = new Character();
$character->set('name', 'Dw');
$t->ok(! $character->isValid()); # This test failed

Can someone tell me what might be the problem here?

Thanks, Andree

+3  A: 

I found it.

Doctrine's validation is turned off by default, so you have to turned it on using the following code:

$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);

In Symfony, I add the following code to /config/ProjectConfiguration.class.php

  public function configureDoctrine(Doctrine_Manager $manager) 
  { 
    $manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
  }
Andree