I have a model with unique field, as showed bellow. The problem is the field is optional and when it is null, I get doctrine's unique error message.
I was expecting it only to validate uniqueness of 'notnull' => true fields.
$this->hasColumn('filename', 'string', 40, array(
'type' => 'string',
'unique' => true,
'length' => '40',
));
Thank you in advance.
Edit: I Disabled validation and it looks like the field is carrying a blank string instead of null:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '' for key 'filename'
So the question now is: How do I enforce null values on blank values...
Edit 2: I did that as workaround. =/
public function preValidate()
{
if(!$this->filename) {
$this->filename = null;
}
}