# Has many - Active Record

**URL:** <https://www.ruby-forum.com/t/has-many-active-record/195752>\
**Category:** Rails\
**Created:** [September 29, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/has-many-active-record/195752 "2010-09-29T15:04:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [September 29, 2010, 3:04pm UTC](https://www.ruby-forum.com/t/has-many-active-record/195752/1 "2010-09-29T15:04:47Z")

</div>

I would like to know which “has\_many” associations my ActiveRecord model  
has.

Example, given this model:

class Post \< ActiveRecord::Base  
has\_many :comments  
end

I need a method that does this:

@associations = Post.has\_many\_associations

@association.each do |a|  
puts a # should print “comments”  
end

Can you help me ? This method exists ? Is it possible ?  
Thanks

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [September 29, 2010, 4:09pm UTC](https://www.ruby-forum.com/t/has-many-active-record/195752/2 "2010-09-29T16:09:03Z")

</div>

not perfect yet, but there is something like this…:

Post.reflect\_on\_association :comments

…that returns a boolean…

Not perfect yet…but helps…

---

<div class="post-metadata">

**Author:** ![andersonleite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@andersonleite](https://www.ruby-forum.com/u/andersonleite)\
**Post date:** [September 29, 2010, 5:49pm UTC](https://www.ruby-forum.com/t/has-many-active-record/195752/3 "2010-09-29T17:49:12Z")

</div>

On Sep 29, 3:09 pm, Anderson L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> not perfect yet, but there is something like this…:
> 
> Post.reflect\_on\_association :comments
> 
> …that returns a boolean…

It should be returning a reflection object. see also the reflections  
method and reflect\_on\_all\_associations

Fred
