# Determining an association type

**URL:** <https://www.ruby-forum.com/t/determining-an-association-type/114381>\
**Category:** Rails\
**Created:** [September 12, 2007, 12:43am UTC](https://www.ruby-forum.com/t/determining-an-association-type/114381 "2007-09-12T00:43:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [September 12, 2007, 12:43am UTC](https://www.ruby-forum.com/t/determining-an-association-type/114381/1 "2007-09-12T00:43:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [September 12, 2007, 12:44am UTC](https://www.ruby-forum.com/t/determining-an-association-type/114381/2 "2007-09-12T00:44:40Z")

</div>

On 9/11/07, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

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

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [September 12, 2007, 1:28am UTC](https://www.ruby-forum.com/t/determining-an-association-type/114381/3 "2007-09-12T01:28:44Z")

</div>

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
