【发布时间】:2021-05-01 16:59:30
【问题描述】:
有一个表结构如下:(主键:user_id,record_id)
+---------+-----------+-------+
| user_id | record_id | value |
+---------+-----------+-------+
| 1 | 1 | 100 |
| 1 | 2 | 200 |
| 2 | 1 | 300 |
| 2 | 2 | 400 |
+---------+-----------+-------+
当我像这样在控制器中通过 eloquent-query 更改 value 参数时:
$playerRecord = Test::where('user_id', '=', $player_id)->where('record_id', '=', '1')->first();
$playerRecord->value = $user_value1;
$playerRecord->save();
我有一个错误:https://flareapp.io/share/47qg8ZEm#F49
如果我在模型中只定义一个主键,那么所有具有此键的记录都会更新,尽管我强制更新了特定记录。
【问题讨论】:
-
你可以在查询中直接使用 update()
-
这能回答你的问题吗? stackoverflow.com/questions/36332005/…
-
似乎这一行抛出一个空结果
Test::where('user_id', '=', $player_id)->where('record_id', '=', '1')->first();