Hiya, I have an array of ActiveRecord objects, I need to grab all records from the array where "section = ''foo''". I''m doing it this way because I don''t want to have to perform two find_by_XXX queries. I successfully did this a while ago but I have forgotten since and don''t have the source code handy. Any help would be appreciated. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 Feb 25, 11:44 pm, chris loper <clo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hiya, > > I have an array of ActiveRecord objects, I need to grab all records > from the array where "section = ''foo''". I''m doing it this way because > I don''t want to have to perform two find_by_XXX queries. > > I successfully did this a while ago but I have forgotten since and > don''t have the source code handy. Any help would be appreciated. > > Thanks.Something like filtered = array.collect { |element| element if element =''foo'' }.compact HTH, --Dean --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Lionel Bouton
2007-Feb-26 08:55 UTC
Re: Filtering through an array of ActiveRecord objects
chris loper wrote the following on 26.02.2007 08:44 :> Hiya, > > I have an array of ActiveRecord objects, I need to grab all records > from the array where "section = ''foo''". I''m doing it this way because > I don''t want to have to perform two find_by_XXX queries. >I may not understand your problem, but can''t you find_by_xxx_and_section(<xxx_value>, ''foo'')? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
chris loper wrote:> Hiya, > > I have an array of ActiveRecord objects, I need to grab all records > from the array where "section = ''foo''". I''m doing it this way because > I don''t want to have to perform two find_by_XXX queries. > > I successfully did this a while ago but I have forgotten since and > don''t have the source code handy. Any help would be appreciated. > > Thanks.You can do this: objects = array.select { |obj| obj.section == ''foo'' } -bob -- 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 -~----------~----~----~----~------~----~------~--~---