-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
We have this code:
class Band
include Mongoid::Document
has_many :albums
end
class Album
include Mongoid::Document
belongs_to :band
end
@bands = Band.includes(:albums).entries
This is great because now I can run @bands.first.albums without hitting the DB.
But now, if we write this includes to the rails cache...
Rails.cache.write('bands', @bands)
...we then read the cache.
bands = Rails.cache.read('bands')
This returns an array of band documents...
...and then we can't get the albums.
bands.first.albums
NoMethodError: undefined method 'albums' for #<Array:0x00000104df50c0>
Is there a special way to cache these eager loaded documents with Rails or Mongoid?
FYI we're using Mongoid 4.