I have a db column which is a serialized Hash
:
class Foo < ActiveRecord::Base
serialize :bar
end
When I store a hash inside of bar that is a few levels deep, the deeper levels do not seem to properly deserialize when I need them. Objects one level deep get deserialzed just fine. However, objects 2 or more levels deep remain YAML classes.
I tried manually deserializing using YAML::load() but got an error saying the argument wasn't an instance of IO.
Does anyone know why the complete Ruby object doesn't deserialize?
EDIT: After further investigation, the problem seems to stem from the fact that I'm calling a virtual attribute from the serialized YAML.
class Foo < ActiveRecord::Base
serialize :bar
end
class Bar < ActiveRecord::Base
attr_accessor :enabled
end
@bars = @foo.bar[:bars]
@bars.each do |bar|
puts bar.enabled
end
yields:
NoMethodError: undefined method `enabled' for #<YAML::Object:0xb6f11844>
from (irb):12
from (irb):11:in `each'
from (irb):11
from :0
Does this mean deserialization isn't "real", ie, the YAML object acts similar to the original object, but it's not an actual instance of that object?