In Yii2, an update interface, if the record in the table has been deleted before executing save(), it will still return ture, whether it is necessary to avoid this situation
1. In yii2, an update interface, if the records in the table have been deleted before executing save(), it will still return ture, whether this situation needs to be avoided. as shown in Figure 1
2. The code is implemented as follows
$animation = InvitationPageElementAnimation::find()->where([
'id' => $id,
])->with(['invitation'])->limit(1)->one();
$executeRes = Yii::$app->db->createCommand('DELETE FROM `invitation_page_element_animations` WHERE id=:id')
->bindValue(':id', $id)
->execute();
Yii::info(
[
$executeRes
],
'$executeRes'
);
try {
$res = $animation->save(false);
Yii::info(
[
$res
],
'$res'
);
if (!$res) {
return [
'code' => 10400,
'message' => '设置动画属性失败',
];
}
return [
'code' => 10000,
'message' => '设置动画属性成功',
'data' => $animation,
];
} catch (Throwable $e) {
Yii::error([
'exception' => get_class($e),
'message' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
], 'application.model.save.exception');
return [
'code' => 10500,
'message' => '数据库操作失败,请联系管理员',
];
}
3. Decide not to adjust for the time being.
