Hello All, I saw the following code in a slide deck and was hoping someone could help me out trying to understand it. def self.up add_column "users", "friends_ids", :text end class Friendship < AR::Base belongs to :user belongs_to :friend def add_to_denormalized_friends user.friends_ids << friend.id user.friends_ids.uniq! end what i don''t get is, friends_ids is text, so how does it get converted to an array so that uniq! can be called on it? it seems like a neat trick and i''d really like to learn it if its real. thanks, binh -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/31/07, Binh Ly <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello All, > > I saw the following code in a slide deck and was hoping someone could > help me out trying to understand it. > > def self.up > add_column "users", "friends_ids", :text > end > > class Friendship < AR::Base > > belongs to :user > belongs_to :friend > > def add_to_denormalized_friends > user.friends_ids << friend.id > user.friends_ids.uniq! > end > > what i don''t get is, friends_ids is text, so how does it get converted > to an array so that uniq! can be called on it? > > it seems like a neat trick and i''d really like to learn it if its real.You don''t show the definition of the User class, it''s possible that user_ids is a composite attribute, which would be done using the composed_of :user_ids, .... declaration. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 10/31/07, Rick DeNatale <rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You don''t show the definition of the User class, it''s possible that > user_ids is a composite attribute, which would be done using the > composed_of :user_ids, .... declaration.Having just said that it''s probably not the case. More likely user_ids is converted in before_save and after_initialize and/or after_find callbacks. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---