Storing objects in Ohm:Model

51 views
Skip to first unread message

Martin Guetlein

unread,
May 5, 2011, 4:07:10 AM5/5/11
to Ohm Ruby
Hi all,

one more thing. I know thats not how redis is supposed to be used,
anyway, is there a more elegant way to store some arbitrary object in
a model? (see my approach below)

Regards,
Martin


MyModel < Ohm::Model

attribute :simple_attribute
attribute :arbitrary_object_serialized

def arbitrary_object
YAML.load(arbitrary_object_serialized)
end

def arbitrary_object=(o)
arbitrary_object_serialized = o.to_yaml
end

end

Michel Martens

unread,
May 5, 2011, 11:15:42 AM5/5/11
to ohm-...@googlegroups.com
Hey,

If you want to serialize the object, that's the way to go. The only
downside is that you won't be able to access individual fields of that
object, but I guess that's ok, right? An alternative without
serialization would be to upgrade the arbitrary object to a model of
its own and store it as a reference.

Reply all
Reply to author
Forward
0 new messages