There was a question that was asked on our IRC channel today about how to get all the associations for an Activerecord model. I’m assuming it was to do some debugging or something, in any case I did a bit of digging around in the Rails docs and it turns out the answer isn’t that hard.

Doing something like :


Will give you all the associations for that model, it’s pretty dirty though and so an easy way to tidy it up is :

    Model.reflect_on_all_associations.collect{ |association|

So, as usual with Rails it was easy as pie, I just am putting this here for future use :)

Edit : Thanks to Darcy for tidying up my previous mess :P