Never been to DZone Snippets before?
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
iterate through each child association of a active record class
1 2 class ActiveRecord::Base 3 def each_child 4 self.class.reflect_on_all_associations.each do |assoc| 5 case assoc.macro 6 when :has_many then send(assoc.name).each { |child| yield child } 7 when :has_one then yield send(assoc.name) 8 end 9 end 10 end 11 end