所以我试图找到所有标签名称为“学校”的位置。Location has_many Tags 和 Tag has_many Locations via a join table 通过 :through 模型方法访问
class Location < ActiveRecord::Base
has_many :location_tags
has_many :locations, :through => :location_tags
end
class LocationTag < ActiveRecord::Base
belongs_to :location
belongs_to :tag
end
class Tag < ActiveRecord::Base
has_many :location_tags
has_many :locations, :through => :location_tags
end
所以这些是我的模型。我知道解决方案将涉及includes
,joins
或类似的东西