这种情况下是否有铁路助手?
您有Survey
个has_many
个问题,has_many
答案。
s = Survey.first
s.answers # => Returns the answers of all the survey questions
我不想在这里重新创建轮子。
答案 0 :(得分:2)
它内置于:
class Survey < ActiveRecord::Base
has_many :questions
has_many :answers, :through => :questions
# ...
end
那就是它。现在,您可以致电survey.answers
,它将获得所有答案。
阅读:through
选项(及其限制)here