activerecord - Rails has_many meta data -
i have model declares multiple has_many
relationships. there meta data available in activerelation such can loop through these has_many
relationships when working model in order see how many has_many
relationships model involved in, , access contents of each there?
some pseudocode (will not run) if helps clarify goal is:
mymodel.has_many_relationships.each |relationship| relationship.contents.each |content| # ... end end
sure can!
try searching "reflect_on_all_associations" in rails documentation!
reflect_on_all_associations(macro = nil) returns array of associationreflection objects associations in class. if want reflect on association type, pass in symbol (:has_many, :has_one, :belongs_to) first parameter. example: account.reflect_on_all_associations # returns array of associations account.reflect_on_all_associations(:has_many) # returns array of has_many associations
Comments
Post a Comment