我正在从使用Paperclip
迁移到现在使用activeStorage
的过程中。
我已经遍历了here提供的迁移指南。
我有一个Logo
模型和一个School
模型。
一个School
has_one_attached :logo
和一个Logo
belongs_to :school
在控制台中,
school = School.find(119)
school.logo.id
# returns this error ::
Module::DelegationError Exception: id delegated to attachment,but attachment is nil
运行的基础查询如下(这是问题)
SELECT "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4 [["record_id",119],["record_type","School"],["name","logo"],["LIMIT",1]]
我不明白查询为什么要在actIVE_STORAGE_ATTACHMENTS
表中搜索包含School
和record_type
中的record_id
的记录宾语。应该在该表中搜索School
类型和我的Logo
对象的id
。
在我的数据库中,我确实有一个Logo
记录,并且该记录的ID被映射到Logo
表的record_id
列,并且该记录有一个{{1} }映射到actIVE_STORAGE_ATTACHMENTS
表上的blob_id
列,其中包含正确图像的信息。
因此,似乎所有数据都正确。
有人知道为什么正在执行的基础SQL查询正在寻找错误的id
和actIVE_STORAGE_BLOBS
,从而导致type
错误吗?