1
我有一個雙重的has_many:通過關係是這樣的:查詢雙的has_many:通過關聯
class Survey < ActiveRecord::Base
has_many :surveyquestions
has_many :questions, through: :surveyquestions
end
class Question < ActiveRecord::Base
has_many :surveyquestions
has_many :surveys, through: :surveyquestions
has_many :kpiquestions, dependent: :destroy
has_many :kpis, through: :kpiquestions
end
class Kpi < ActiveRecord::Base
has_many :kpiquestions
has_many :questions, through: :kpiquestions
end
現在我想查詢具有特定survey_id
和特定kpi_id
問題,但我不知道該如何查詢這個?
謝謝,這將是正確的查詢:'Question.includes(:調查:關鍵績效指標)。凡(:調查=> {:ID => 1},::kpis => {:id => 1})' – John