Introspecting Active Record Associations

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

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 :slight_smile:

http://rails.rubyonrails.com/classes/ActiveRecord/Reflection/ClassMethods.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

On 1/12/06, Dan W. [email protected] 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.

Thanks very much both of you. Thats perfect.

Cheers,

Dan

On 1/12/06, Jeremy E. [email protected] wrote:

Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Dan W.
http://www.danwebb.net