我有以下型号:
class Foo
has_and_belongs_to_many :bars
end
class Bar
has_and_belongs_to_many :foos
end
每个代表Foo
实例的文档都有一个名为 的数组字段bar_ids
。每当从数据库中检索到 Foo 对象时,Mongoid 也会检索该对象的内容bar_ids
。当文档有 1000 个 id 时,这可能会导致性能问题,即
> Foo.first
#<Foo _id: 4fed60aa2bdf061c2c000001, bar_ids: [1, 2, 3.... 5000]>
在大多数情况下,我不需要加载bar_ids
. 有没有办法可以指示模型延迟加载bar_ids
?