从父属性构建查询

时间:2013-02-15 21:08:39

标签: ruby-on-rails ruby postgresql

从我试图制作的查询中获取以下错误 "缺少FROM子句条目"

基本上,我的问题有很多答案,我试图通过' x'来获取属于问题的所有答案。类别

Answer.joins(:question).
from('answers').
where(:question => {:category => @category}).
sort_by(&:created_at).
reverse.
paginate(:page => params[:page], :per_page => 20)

1 个答案:

答案 0 :(得分:1)

尝试:

Answer.joins(:question => :category).where...

怎么样:

Answer.joins(question: category).where("categories.name = ?", @category).order("answers.created at ASC").paginate(page: params[:page], per_page: 20)