Quickly finding model associations in rails

In Jan-2011, at my internship, I got a chance to work on a really complex application. And I had to get upto speed with everyone else by understanding the app and the reasons behind certain decisions. The one i worked on had more than two dozen models. Thanks to my commandLineFu, I accidentally, found a trick to list associations between models in a rails app in a readable way. And it's very simple.

From the root of the app (can be done from anywhere, but i'll just say I'm in the root of the app).

grep -ri "has_many" ./

Assuming you don't have the text "has_many" anywhere else in the app. If you do, just change ./ to app/models
The same can be done for belongs_to

grep -ri "belongs_to" ./

You'll be surprised to find that bash (ubuntu guy here!) gives you a really nice readable view of the associations. Each line, when read fully, shouts out the association :)
Posted