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>> 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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jan-06 09:16 UTC
Re: serialized attribute converting to string on reload
On Jan 6, 5:23 am, RailinAndWailin <waugustyn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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> 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-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
RailinAndWailin
2010-Jan-06 15:45 UTC
Re: serialized attribute converting to string on reload
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. On Jan 6, 1:16 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 6, 5:23 am, RailinAndWailin <waugustyn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > > 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 > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Jan-06 15:58 UTC
Re: Re: serialized attribute converting to string on reload
On 6 Jan 2010, at 15:45, RailinAndWailin 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> I even tried .to_yaml when setting the attribute. Same thing keeps > happening. > > On Jan 6, 1:16 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: >> On Jan 6, 5:23 am, RailinAndWailin <waugustyn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 >> >>> 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 >> >> > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
RailinAndWailin
2010-Jan-06 16:11 UTC
Re: serialized attribute converting to string on reload
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? On Jan 6, 7:58 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 6 Jan 2010, at 15:45, RailinAndWailin 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 > > > I even tried .to_yaml when setting the attribute. Same thing keeps > > happening. > > > On Jan 6, 1:16 am, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > > wrote: > >> On Jan 6, 5:23 am, RailinAndWailin <waugustyn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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 > > >>> 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 > > > -- > > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.