Peter Marks
2007-Sep-25 23:00 UTC
Constructing an array of objects from an array of objects
On line 1 I have constructed an array of Event objects, which belong_to an Account object. How might I construct an array of Account objects from this array of Event objects on line 2? 1 notices = Event.find(:all, :conditions => ["account_id IN (?) AND name = ?", self.account_ids, account_notice_sent'']) 2 return notices.account -- 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 -~----------~----~----~----~------~----~------~--~---
William Pratt
2007-Sep-25 23:17 UTC
Re: Constructing an array of objects from an array of objects
Use collect: accounts = notices.collect{|n| n.account} You may want to add :include => ''account'' to your Event.find to eager load the accounts. Peter Marks wrote:> On line 1 I have constructed an array of Event objects, which belong_to > an Account object. How might I construct an array of Account objects > from this array of Event objects on line 2? > > 1 notices = Event.find(:all, :conditions => ["account_id IN (?) AND name > = ?", self.account_ids, account_notice_sent'']) > 2 return notices.account >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter Marks
2007-Sep-26 00:50 UTC
Re: Constructing an array of objects from an array of objects
Exactly what I was looking for. Thanks William :) -- 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 -~----------~----~----~----~------~----~------~--~---