モデルの beforeSave() メソッドで別のモデルのレコードを保存しようとしています。save() メソッドが Save() の前に他のモデルを呼び出すことを期待していましたが、そうではありません。これはバグですか、それとも単に何かを見逃しているのでしょうか?ここにいくつかのコードがあります。
運用モデル
public function beforeSave(){
if(parent::beforeSave()){
if($this->isNewRecord){
$this->creation_date=$this->modification_date=time();
$cur=Currencies::model()->find('LOWER(short)=?',array('usd'));
if($cur->id!=$this->currency_id){
$conv_cours=Currencies::model()->findByPk($this->currency_id);
$this->ammount_usd=round(($this->ammount*$conv_cours->buy)/$cur->sell,4);
}else{
$this->ammount_usd=$this->ammount;
}
}else{
$this->modification_date=time();
}
$opType=OperationType::model()->findByPk($this->operation_type);
$log=new ActionLogs;
$log->comment=Yii::app()->user->name.' добавил '.$opType->name;
/*$log->logtime=time();
$log->user_id=Yii::app()->user->id;*/
$v=1;
$log->save ();
return true;
}else{
return false;
}
}
そして別のモデル beforeSave()
public function beforeSave(){
if(parent::beforeSave()){
if($this->isNewRecord){
$this->logtime=time();
$this->user_id=Yii::app()->user->id;
}
return true;
}else{
return false;
}
} ありがとう。