Testing associations with factory girl

Associations are very important when we are working with relational databases. Writing relations in models is easy but when it comes testing them, it is a painful task. Factory girl associations makes this easy. Before going into details, lets get the basics right. What is Factory Girl?    Factory_girl is a fixtures replacement with a … Continue reading Testing associations with factory girl

How to get all associted models of rails model

I have Site Model and i wanted to find all associated models of Site model which are having belongs_to relationship.After doing lot headache, here is the solution i foundhas_many models of Site Model Site.reflect_on_all_associations.map{|mac| mac.class_name if mac.macro==:has_many}.compact=> ["Layout", "User", "SubmenuLink", "Snippet", "Asset"]belongs_to model of Site ModelSite.reflect_on_all_associations.map{|mac| mac.class_name if mac.macro==:belongs_to}.compact=> ["User", "Page", "User"]To get all associationsSite.reflect_on_all_associations.map{|mac| … Continue reading How to get all associted models of rails model