# Introspecting Active Record Associations

**URL:** <https://www.ruby-forum.com/t/introspecting-active-record-associations/52293>\
**Category:** Rails\
**Created:** [January 12, 2006, 4:45pm UTC](https://www.ruby-forum.com/t/introspecting-active-record-associations/52293 "2006-01-12T16:45:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [January 12, 2006, 4:45pm UTC](https://www.ruby-forum.com/t/introspecting-active-record-associations/52293/1 "2006-01-12T16:45:06Z")

</div>

Hi,

I’m looking into write scaffold generators that will, amoung other  
things, scaffold active record associations (eg. generate select  
boxes for belongs\_to where you can choose a parent object) for quicker  
prototyping. But…

My question is: Is there anyway of finding out what associations  
exist from examining the lodel classes themselves or indeed any other  
way of finding out this information?

There’s nothing obvious from looking at the RDOCs and Im poised to  
delve into the rails source but Id rather not because the association  
code is pretty meaty.

Anyone got any clues?

Thanks,

–  
Dan W.  
[http://www.danwebb.net](http://www.danwebb.net)

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [January 12, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/introspecting-active-record-associations/52293/2 "2006-01-12T16:51:13Z")

</div>

> delve into the rails source but Id rather not because the association  
> code is pretty meaty.
> 
> Anyone got any clues?

You just didn’t look hard enough 🙂

[http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/ClassMethods.html](http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/ClassMethods.html)  
[http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/MacroReflection.html](http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/MacroReflection.html)

(kidding, there are a ton of hidden gems and I find new things all the  
time)

good luck!

–  
rick  
[http://techno-weenie.net](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [January 12, 2006, 6:47pm UTC](https://www.ruby-forum.com/t/introspecting-active-record-associations/52293/3 "2006-01-12T18:47:07Z")

</div>

On 1/12/06, Dan W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m looking into write scaffold generators that will, amoung other  
> things, scaffold active record associations (eg. generate select  
> boxes for belongs\_to where you can choose a parent object) for quicker  
> prototyping. But…

Take a look at the Scaffolding Extensions plugin for a start. It  
doesn’t work with the scaffold generator, but it will probably help  
give you an idea of what you need to change.

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [January 12, 2006, 7:38pm UTC](https://www.ruby-forum.com/t/introspecting-active-record-associations/52293/4 "2006-01-12T19:38:29Z")

</div>

Thanks very much both of you. Thats perfect.

Cheers,

Dan

On 1/12/06, Jeremy E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Dan W.  
[http://www.danwebb.net](http://www.danwebb.net)
