ferllings
(Ferllings)
March 9, 2011, 10:24am
1
Hi,
I’m trying to use transaction in my controler, using this example:
http://www.yiiframework.com/doc/guide/1.1/en/database.ar#using-transaction-with-ar
But When the validation fails (for a missing field for exemple), the errorSummary is not displayed anymore.
Every indication about the validation error is missing.
If I remove the transaction, everything is back to normal.
Any idea?
–Cédric
zaccaria
(Matteo Falsitta)
March 9, 2011, 10:34am
2
You should not try to save if validation fails.
The transaction is just a safety more in case of error while saving valid models, but is better to do something like:
$valid= $model1->validate();
$valid= $model2->validate() && $valid;
$valid= $model3->validate() && $valid;
$valid= $model4->validate() && $valid;
if ($valid)
{
save all with transaction!
}
Using this schema you will never try to save a model if they are not all valid. The question of validation result independent from the transaction.
zaccaria:
You should not try to save if validation fails.
The transaction is just a safety more in case of error while saving valid models, but is better to do something like:
$valid= $model1->validate();
$valid= $model2->validate() && $valid;
$valid= $model3->validate() && $valid;
$valid= $model4->validate() && $valid;
if ($valid)
{
save all with transaction!
}
Using this schema you will never try to save a model if they are not all valid. The question of validation result independent from the transaction.
I’m having a similar problem using transactions. I understand this part about how to test validation, but how do you send specific validation errors back to the form so that
CHtml::error($model,$attribute);
will display them? Or is there another route you need to go to display them?