i’m creating my Doctrine record this way:
$user = new User();
$user->fromArray($_POST);
$user->save();
This throws an exception:
Uncaught exception 'Doctrine_Validator_Exception' with message 'Validation failed in class User 1 field had validation error: * 1 validator failed on dni (type)
Of course, the “dni” field is of type: integer, and the HTTP POST has all the values as strings. This is what makes the validation fail. The only way of passing the validation is doing this:
$_POST['dni'] = (int) $_POST['dni'];
But it “feels” wrong.
As a note, I’m working with Doctrine integrated into CodeIgniter. This didn’t ever happened to me when worked with Symfony.
Many thanks.
This is old but unanswered so here it is:
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, VALIDATE_ALL & ~VALIDATE_TYPES);You can instruct Doctrine to validate all or no combination of: Types (your issue), Length, Constraints, All and None.
You can do it on the global level.
Probably also on the connection level.
And definetly per table but I could not find it on the doctrine orm documentation.
and you don’t need to worry about having a wrong data type inserted in the database, the db won’t let you and that’s outside of doctrine’s hand.