我试图理解为什么我找不到附加到记录的文件,因此我在回调期间after_save
在代码中的某个点放置了断点(重要的是要注意这种情况发生时)。以下是在暂停期间进行一些调用的输出:
0> self.inspect
=> #<BinSet id: 1131, name: "test upload", ...>
0> self.bins_table.download
=> Error: the evaluation of `self.bins_table.download` failed with the exception 'ActiveStorage::FileNotFoundError'
0> self.bins_table.attached?
=> true
0> self.reload
=> Error: the evaluation of `self.reload` failed with the exception 'Couldn't find BinSet with 'id'=1131'
0> self.id
=> 1131
0> self.persisted?
=> true
0> BinSet.find(1131)
=> Error: the evaluation of `BinSet.find(1131)` failed with the exception 'Couldn't find BinSet with 'id'=1131'
0> self.save!
=> true
0> self.id
=> 1131
0> BinSet.find(1131)
=> Error: the evaluation of `BinSet.find(1131)` failed with the exception 'Couldn't find BinSet with 'id'=1131'
回想一下,这是在 期间发生的after_save
,这意味着记录已被保存。它已被分配一个 ID 且self.persisted?
为true
,但在数据库中找不到它。此时记录在哪里?
如果您参考文档
after_save
(链接的文档已弃用,但这仍然适用于当前回调),您将看到以下内容:如果您需要关闭数据库事务以进行操作,我会使用
after_commit
.