Hi, Let''s say I have an ActiveRecord::Base class and I want to be able to call a method on an Array of these items. For instance, perhaps there''s a class called Country and another called business, and I''d like to be able to do something like great_white_north = Country.find_by_name(''Canada'') canuck_enterprises = great_white_north.businesses countries = Country.find_by_name([''Canada'',''UK'',''Australia'') we_love_the_queen_enterprises = countries.businesses So I need to somehow extend the Array class I think. Tips? Ben --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Ben,> great_white_north = Country.find_by_name(''Canada'') > canuck_enterprises = great_white_north.businesses > > countries = Country.find_by_name([''Canada'',''UK'',''Australia'') > we_love_the_queen_enterprises = countries.businesseswe_love_the_queen_enterprises = countries.map { |c| c.businesses }> So I need to somehow extend the Array class I think. Tips?No you don''t ... :) Regards Florian --~--~---------~--~----~------------~-------~--~----~ 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 Jun 18, 2007, at 2:03 PM, Ben Nevile wrote:> Hi, > > Let''s say I have an ActiveRecord::Base class and I want to be able to > call a method on an Array of these items. For instance, perhaps > there''s a class called Country and another called business, and I''d > like to be able to do something like > > great_white_north = Country.find_by_name(''Canada'') > canuck_enterprises = great_white_north.businessesAssuming you have: class Country < ActiveRecord::Base has_many :businesses end Then you''re practically already there!> countries = Country.find_by_name([''Canada'',''UK'',''Australia'') > we_love_the_queen_enterprises = countries.businesses >countries = Country.find(:all, :conditions => [ ''name IN (?)'', [''Canada'', ''UK'', ''Australia''] ]) we_love_the_queen_enterprises = countries.map(&:businesses).flatten> > So I need to somehow extend the Array class I think. Tips? > Ben-Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---