$copy= new Record();
$copy->attributes= $this->attributes;
$copy->save();
Is also better to do a function for it and not do in the beforesave, because it would be called even in the beforesave of the copy generating a recursive save of copies.
You’re right, but still what I’m trying should work. I looked at the save function inside CActiveRecord.php, and I noticed that there is no call to beforeSave!!
public function save($runValidation=true,$attributes=null)
{
if(!$runValidation || $this->validate($attributes))
return $this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
else
return false;
}
I’ve added print statements in my before function and in this save function and noticed that save() is first executed, and after that my beforeSave.
Any suggestion whats going on here ?
UPDATE: found the solution. Before save is called inside the insert(…) or update(…) so the check if its a new record is already done. So I’m using now afterValidate, and it works!!