# Getting associations list

**URL:** <https://www.ruby-forum.com/t/getting-associations-list/115073>\
**Category:** Ruby\
**Created:** [September 20, 2007, 11:37am UTC](https://www.ruby-forum.com/t/getting-associations-list/115073 "2007-09-20T11:37:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![akiross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@akiross](https://www.ruby-forum.com/u/akiross)\
**Post date:** [September 20, 2007, 11:37am UTC](https://www.ruby-forum.com/t/getting-associations-list/115073/1 "2007-09-20T11:37:41Z")

</div>

Hi there,  
how can I retrieve a list of associations for a given Active Record?  
I mean, having:

class Foo \< ActiveRecord::Base  
has\_one :bar  
has\_one :baz  
belongs\_to :gosh  
belongs\_to :gulp  
end

get lists of all has\_one associations, one for belongs\_to  
associations, etc? (or a list with every association, if possible  
distinguishing the kind of assoc.).

On documentation i found that has\_one adds some methods (.bar, .bar=,  
.build\_bar etc) to Foo, but actually doing Foo.column\_names or  
foo.attribute\_names doesn’t give me any of the above fields (if none  
has been built, it seems).

I need to give user the ability to specify one of these associations,  
but without hard-coding, so i need to retrieve such lists for each  
ActiveRecord.

Thanks

---

<div class="post-metadata">

**Author:** ![akiross](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@akiross](https://www.ruby-forum.com/u/akiross)\
**Post date:** [September 20, 2007, 12:25pm UTC](https://www.ruby-forum.com/t/getting-associations-list/115073/2 "2007-09-20T12:25:48Z")

</div>

Ok, i found reflections. Sorry for the disturb
