新手问题 ActiveStorage 的若干问题:1. 如何在 where 语句里判断是否 attached? 2. purge 后, attached? 为 true 但是 blob 是 nil

imwildcat · October 22, 2018 · Last by ice_7 replied at October 24, 2018 · 1749 hits

ActiveStorage 的若干问题:

  1. 如何在 where 语句里判断是否 attached?
    https://stackoverflow.com/questions/52418114/how-to-query-records-that-have-an-activestorage-attachment 这有说,但是需要先把 ids 请求出来

  2. purge 后,attached? 为 true 但是 blob 是 nil。
    类似这个问题:https://stackoverflow.com/questions/50223308/activestorage-record-returns-attached-as-true-but-the-blob-is-nil-how-do-i-re 是不是可以去提 issues 了呢?

现在项目上线了但是非常后悔用 Active Storage。感觉实在是太不好用了

where 的话,不能直接用 你的模型来取吧(((。。。。他又没写在你的表上(

  1. stackoverflow 的回答不是挺好的,用 joins。
  2. 先看看有没有人提过,如果没有可以提,GitHub 提交 issue 的时候有模版。

第二个问题应该不会吧,我使用时候是没出现过 purge 之后还会出现 attached?为 true 的情况

另外,active_storage_attachments 和 active_storage_blobs 表里的数据可以单独创建,然后和其他对象关联,就会出现你第二个问题中提到的 stackoverflow 中的例子,active_storage_attachments 中的记录对应的 active_storage_blobs 记录不存在,那 purge 就失败了

You need to Sign in before reply, if you don't have an account, please Sign up first.