Sunday, December 16, 2007

ActiveRecord::Base#reflect_on_all_associations

You need this method. It gives you an an array of AssociationReflections, which are handy little reporting objects giving you all the stuff you're likely to need to know about an AR association class. You can find out if it's :has_many or :belongs_to, you can distinguish a regular :has_many from a :has_many :through =>, it basically makes any kind of AR magic you might need for a plugin easy as toast. (I was going to say pie, but let's face it, pie is hard compared to toast. You'd have to be drunk and retarded to fuck up toast.)