Last Updated: February 25, 2016
·
702
· mehulkar

Checking model associations in Rails 3

I don't like looking through my models to see what associations are set up. It's distracting to look through those, especially if the models are complex. I always forget this neat trick, so writing it down.

object_instance.reflections.each do |reflection|
  puts "#{reflection[0]}: #{reflection[1].macro}"
end

reflections[0] is the associated model and reflections[1].macro is the type of association.