我有两个相关的模型:
class Facility < ActiveRecord::Base
has_and_belongs_to_many :investigators, class_name: "Person"
has_and_belongs_to_many :technicians, class_name: "Person"
end
和
class Person < ActiveRecord::Base
has_and_belongs_to_many :facilities
end
如果我实例化调查员和技术员,我可以使用例如获得与特定设施相关联的每个人的数量
numtechs = myfacility.technicians.size
numinvests = myfacility.investigators.size
等等。但是我如何返回与设施相关联的总人数。试
numpeople = myfacility.people.size
似乎不起作用。
有没有办法一口气做到这一点?
谢谢。