Determining an association type

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

On 9/11/07, Pat M. [email protected] wrote:

=== works for this
ActiveRecord::Associations::HasManyAssociation === company.sites

Pat

On Sep 12, 2007, at 12:40 AM, Pat M. 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

There’s API for that:

Company.reflect_on_association(:sites).macro == :has_many

– fxn