When I find() some model, and update some fields and later save() it, i got this error:
[color="#FF0000"]General error: 1292 Incorrect datetime value: ‘17/09/2009 14:04:26’ for column ‘DataInserido’ at row 1[/color]
This occurs because i format my date in afterFind().
One solution for this is to check isNewRecord() inside de beforeSave().
But would be nicer if I can tell to activerecord this: "This field is read only, can be set only the creation not in update. So, ignore this field in update statement".
Well ive been looking at this and it looks like its not within Yiis functionality, but it looks like you can create a Validator for this. looks like the best aproach to me, I also though about maybe creating a Behavior but it looks smooter if you can add this kind of things to the rules() method in the model:
You may like it, something like:
public function rules()
{
return array(
array('DataInserido, DataAtualizado', 'contraints', 'readOnly'=>true),
);
}
And for your exact case:
public function rules()
{
return array(
array('DataInserido, DataAtualizado', 'contraints', 'readOnly'=>true, 'on'=>'update'),
);
}
Well I like the idea of a validator as you can not only use it for that but extend it for some other validatios alike, you can also use the validator for all other models and you wont need to write a