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
>> me.equipment
+----+--------------+--------------------------+-------+-------+-------
+------+-------------------------+-------------------------+
| id | character_id | rhand | lhand | chest | pants
| head | created_at | updated_at |
+----+--------------+--------------------------+-------+-------+-------
+------+-------------------------+-------------------------+
| 1 | 1 | #<Weapon:0x7fa10db2b988> | | |
| | 2010-01-06 05:09:21 UTC | 2010-01-06 05:09:51 UTC |
+----+--------------+--------------------------+-------+-------+-------
+------+-------------------------+-------------------------+
1 row in set
>> me.equipment.save
=> true
>> me.equipment.reload
+----+--------------+-------+-------+-------+-------+------
+-------------------------+-------------------------+
| id | character_id | rhand | lhand | chest | pants | head |
created_at | updated_at |
+----+--------------+-------+-------+-------+-------+------
+-------------------------+-------------------------+
| 1 | 1 | 6 | | | | |
2010-01-06 05:09:21 UTC | 2010-01-06 05:09:51 UTC |
+----+--------------+-------+-------+-------+-------+------
+-------------------------+-------------------------+
1 row in set
On Jan 6, 5:23 am, RailinAndWailin <waugustyn...@gmail.com> wrote:
> Hello,
>
> Anybody help me out? I done googled it good and didn't find anything
> (which should mean that I've done something wrong).
>
What's in your model ?
Fred
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.
On Jan 6, 1:16 am, Frederick Cheung <frederick.che...@gmail.com>
wrote:
> 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
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
On Jan 6, 7:58 am, Frederick Cheung <frederick.che...@gmail.com>