I've just revisited this code (I put up with the "press twice" bug for a while now!
I've re-written some of my code and this issue that I reported above still exists.
* I use this CSaveRelationsBehavior to set the line items to a Request record.
* I would like to populate the SUM of the line items on the Request record.
* For this to occur it only sets the correct SUM on the 2nd save of the record.
I have worked out (I think?
that this happens because Request record is being saved prior to the line items/related records, thus when the SUM is performed the old value is displayed.
I have tried using both true and false for transactional mode, but I see no difference.
I am attempting to perform the following calculation on the beforeSave() of the Request.
$query = Yii::app()->db->createCommand()->select('SUM(total) as SUM')->from(ServiceRequestStockTrans::model()->tableName())->where("sr_id=:sr_id", array('sr_id'=>$this->id))->queryRow();
So I know it's all about the timing and when the variables are set, and it makes sense why it occours... But I am not sure about the best approach to solve it? Do you have any suggestions?