我有这些多态关系:
staff:
id - integer
name - string
orders:
id - integer
price - integer
photos:
id - integer
path - string
imageable_id - integer
imageable_type - string
在 Controller 中:
public function example() {
\DB::beginTransaction();
try {
$staff = Staff::findOrFail(1);
$row = $staff->photos()->create([ 'path' => 1 ]);
$row->path = 2;
$row->save();
abort(445);
} catch( \Exception $e ) {
\DB::rollback()
}
}
正如预期的那样,必须从照片表中删除当前行,但它仍然存在,路径 = 2
我会马上思考吗?或者这是一个误解?
最佳答案
如果它不回滚事务,则有一种可能是您的表将 MyISAM
作为引擎,因为 MyISAM 表不支持回滚。
因此,请仔细检查表的引擎是否正确设置为 InnoDB
。
关于mysql - Laravel 的回滚事务是否支持多态关系?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38562296/