Pat_Maddox
(Pat Maddox)
1
I'd like to know if an association is a has_many, belongs_to, or
has_one. I was hoping I could do something like this:
company.sites.is_a? ActiveRecord::Associations::HasManyAssociation
however that doesn't work, it says that sites is just an array.
Anyone know how I can determine what kind of association I'm working
with?
Pat
Pat_Maddox
(Pat Maddox)
2
=== works for this
ActiveRecord::Associations::HasManyAssociation === company.sites
Pat
fxn
(Xavier Noria)
3
There's API for that:
Company.reflect_on_association(:sites).macro == :has_many
-- fxn