# Programmatic way to find associations? (ActiveRecord)

**URL:** <https://www.ruby-forum.com/t/programmatic-way-to-find-associations-activerecord/165254>\
**Category:** Rails\
**Created:** [April 10, 2009, 10:37pm UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-associations-activerecord/165254 "2009-04-10T22:37:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [April 10, 2009, 10:37pm UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-associations-activerecord/165254/1 "2009-04-10T22:37:34Z")

</div>

Is there a programmatic way to find the different associations that an  
particular model has?

For example, if I have the following:

class File \< ActiveRecord::Base  
belongs\_to :directory  
has\_many :comments  
end

is there a way to get the list of symbols/strings that this class has  
associated under the has\_many association?

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [April 10, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-associations-activerecord/165254/2 "2009-04-10T22:49:55Z")

</div>

On Apr 10, 9:37 pm, gm gm [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is there a programmatic way to find the different associations that an  
> particular model has?

Take a look at YourClass.reflections and the various reflect\_on\_xxx  
methods

Fred

---

<div class="post-metadata">

**Author:** ![gmoniey](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/6a8cbe/32.png) [@gmoniey](https://www.ruby-forum.com/u/gmoniey)\
**Post date:** [April 11, 2009, 6:26am UTC](https://www.ruby-forum.com/t/programmatic-way-to-find-associations-activerecord/165254/3 "2009-04-11T06:26:37Z")

</div>

Thanks…I could never find that on my own…
