I have the following models:
class Foo
has_and_belongs_to_many :bars
end
class Bar
has_and_belongs_to_many :foos
end
Each document representing the Foo
instance has an array field called bar_ids
. When ever a Foo object is retrieved from the DB, Mongoid retrieves the contents of the bar_ids
also. When the document has 1000s of ids this can cause performance issues, i.e.
> Foo.first
#<Foo _id: 4fed60aa2bdf061c2c000001, bar_ids: [1, 2, 3.... 5000]>
In most cases I don't need to load the bar_ids
. Is there way I can instruct the model to lazy load the bar_ids
?