我需要在afterSave()方法中更新数据。
SummaryField是ActiveRecord类
我正在尝试使用此代码:
public function afterSave($insert, $changedAttributes)
{
$sumField = new SummaryField();
if ($insert==true)
{
$sumField->field_id = $_POST['Scientist']['field_name'];
$sumField->scientist_id = $this->scientist_id;
$sumField->save();
}
else
{
$sumField = SummaryField::findOne($this->scientist_id);
$sumField->field_id = $_POST['Scientist']['field_name'];
$sumField->scientist_id = $this->scientist_id;
$sumField->update();
}
}
因此,save()方法正常工作,但是当我们调用ELSE语句时:
Creating default object from empty value
就此$sumField->field_id = $_POST['Scientist']['field_name'];
我不能使用新的stdClass();
答案 0 :(得分:0)
可能是你必须为find ..
定义正确的查询尝试以这种方式指示column_name ..
$sumField = SummaryField::find()->where(['scientist' => $this->scientist_id])->one();