In my building model I have “belongs_to :site” and in my equipment
model I have “belongs_to :building”.
How do I find all pieces of equipment that belong to a particular
customer?
I tried something like Equipment.find(:all, :include =>
[ :building, :site ], :conditions => ‘customer_id = 1’), but of course
that doesn’t work because there’s nothing about :site in the equipment
model. I also tried to put “:include => :site” in the “belongs_to” in
the building model, but I got an error saying that the association
named “:site” wasn’t found.
In my building model I have “belongs_to :site” and in my equipment
model I have “belongs_to :building”.
How do I find all pieces of equipment that belong to a particular
customer?
Do you also have:
class Site
has_many :buildings
end
and so on?
Thanks!
Your table names should be plural (e.g., ‘sites’ and ‘buildings’)
unless you have overridden this with set_table_name in your model.
but even if that works as-is, you should consider the other parts
(adding “has_many” associations to mirror your “belongs_to”; having a
customer model and table; pluralizing your tables) as means to avoid
future aggravation.