【发布时间】:2019-03-24 22:13:38
【问题描述】:
使用 Rails 5.2 和 Active Storage,我设置了一个 Item 类和一些 images:
class Item < ApplicationRecord
has_many_attached :images
end
我想使用ActiveRecord::QueryMethods.includes 来急切加载images,这是带有has_many 的非常标准的Rails 东西,但是:
Item.includes(:images)
=> ActiveRecord::AssociationNotFoundError ("Association named 'images' was not found on Item; perhaps you misspelled it?")
Item.includes(:attachments)
=> ActiveRecord::AssociationNotFoundError ("Association named 'attachments' was not found on Item; perhaps you misspelled it?")
Item.includes(:active_storage_attachments)
=> ActiveRecord::AssociationNotFoundError ("Association named 'active_storage_attachments' was not found on Item; perhaps you misspelled it?")
知道如何让它工作吗?
【问题讨论】:
标签: ruby-on-rails activerecord rails-activestorage