i found strange issue with AR. First what i did i selected my table with relations checked if it exists. Second made insert into database after inserting i need to update that record. Issue is that i need to make new selection of active record with resetScope.
You probably face the same problem i had. Do you use afterSave() ? Then isNewRecord still is true. If you are careful, you can change it to false (that’s what would happen internally in AR after afterSave() was called anyway). I did it like this:
if ($this->isNewRecord) {
$this->isNewRecord=false;
$this->saveAttributes(array(
'invoice_number'=>'BCR-'.$this->id,
));
}
Just make sure, you put this after the last check for isNewRecord in your code, of course.