Hello,
Anybody help me out? I done googled it good and didn't find anything
(which should mean that I've done something wrong).
Not much code to talk about here, quite simply I have an attribute
that is serialzied and when I update it, irb shows the object and my
methods run on it as it were indeed so. Though when I reload it
changes the data to a string. Not yaml, just one digit, the id of the
object i had serialized. Don't think that's pertinent, most likely
that was just the first listed attribute of the stored object.
Anybody have any idea why this would happen? (hirb styling in the
below posted irb):
Item.find(6).equip(me)
=> true
After trying this over and over I noticed that this only tends to
happen with ActiveRecord::Base Objects.
Any object that I created alone (in irb), i serialized and it worked
out fine.
The model doesn't constrain the serialized attribute to any sort of
type, though it had originally (and then throw the
SerializationTypeMimatch after reload). I've rewritten the setter
several ways though there is no pre-assignment logic on the variable
at all....no real way to be more specific without posting alot of code
here.
I've tried serializing various instance of ActiveRecord models into
this attribute and they all end up the same way. All except for
classes not inherting from ActiveRecord::Base. I have serialized
attributes (as Hashes) that work fine elsewhere...I dunno.
I even tried .to_yaml when setting the attribute. Same thing keeps
happening.
After trying this over and over I noticed that this only tends to
happen with ActiveRecord::Base Objects.
Any object that I created alone (in irb), i serialized and it worked
out fine.
The model doesn't constrain the serialized attribute to any sort of
type, though it had originally (and then throw the
SerializationTypeMimatch after reload). I've rewritten the setter
several ways though there is no pre-assignment logic on the variable
at all....no real way to be more specific without posting alot of code
here.
I've tried serializing various instance of ActiveRecord models into
this attribute and they all end up the same way. All except for
classes not inherting from ActiveRecord::Base. I have serialized
attributes (as Hashes) that work fine elsewhere...I dunno.
This is probably to do with the reloading of activerecord classes. Why would you serialize an activerecord object rather than just storing the id (or a hash of its attributes)
Fred
I had just the id in there before and could go back to doing that, I
was looking for a "cleaner" (as in less code and query) way of going
about it. Serializing it got rid of a couple of query's which just
obtained attributes (static class) from the object. I very well could
just redo it with having Hashes instead... something like {id:=>..,
attr=>..}.
I just wondered if this may had been something I had done incorrectly
or not.
I suppose when I reload the model, ActiveRecord tries to reload the
value of that field or something?