0

そのため、「学校」という名前のタグを持つすべての場所を見つけようとしています。Location has_many Tags および Tag has_many Locations :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またはそれらの線に沿った何かが含まれることを私は知っています

4

2 に答える 2

1

Tag.where(:name => 'school').locations

于 2013-08-16T20:35:09.590 に答える
0

とった。

Location.where(query_stuff).includes(:tags).where(:tags => { :name => "school" })
于 2013-08-27T23:54:47.290 に答える