Greg Willits wrote:
I'm trying to serialize, err Marshal, an AR model with associations
to a db field.
Seems simple enough to start with. After a dump I have a bunch of
Binary data in my field, and looking at with a Hex viewer, it seems
to have AR-looking stuff.
However, when I try to re-constitute the model, I get an error
"undefined class/module Xyz" where Xyz is one of the associated models.
This is in Dev mode, so, figuring this just an issue of Rails not
having loaded that model file yet, I just tossed a require for each
of the associated models at the top of the controller file doing the
Marshal.load to ensure they are loaded first.
It's simple, and it worked, but I'm wondering if there is another
solution, or, "yep, that's how we fix that"
I haven't peered into how Marshal works itself.
But I imagine the problem is that it bypasses const_missing,
so rails' clever file_name const-get-ing doesnt work.
d = RudeQueue.get(:rar)
ArgumentError: undefined class/module Event
from (irb):3:in `load'
=> Event(id: integer, name: string, description: text, start_date: date,
end_date: date, created_at: datetime, updated_at: datetime)
=> #<Event id: 1, name: "blah", description: nil, start_date: nil,
end_date: nil, created_at: "2008-06-22 15:20:35", updated_at:
So I imagine there is no clever way to fix it,
except to ensure that the related class is already loaded.