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.
Written by Mehul Kar
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#