I''d like to know if an association is a has_many, belongs_to, or has_one. I was hoping I could do something like this: company.sites.is_a? ActiveRecord::Associations::HasManyAssociation however that doesn''t work, it says that sites is just an array. Anyone know how I can determine what kind of association I''m working with? Pat --~--~---------~--~----~------------~-------~--~----~ 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 9/11/07, Pat Maddox <pergesu-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to know if an association is a has_many, belongs_to, or > has_one. I was hoping I could do something like this: > > company.sites.is_a? ActiveRecord::Associations::HasManyAssociation > > however that doesn''t work, it says that sites is just an array. > Anyone know how I can determine what kind of association I''m working > with? > > Pat >=== works for this ActiveRecord::Associations::HasManyAssociation === company.sites Pat --~--~---------~--~----~------------~-------~--~----~ 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 Sep 12, 2007, at 12:40 AM, Pat Maddox wrote:> > I''d like to know if an association is a has_many, belongs_to, or > has_one. I was hoping I could do something like this: > > company.sites.is_a? ActiveRecord::Associations::HasManyAssociationThere''s API for that: Company.reflect_on_association(:sites).macro == :has_many -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---