Don*_*n P 6 ruby-on-rails rails-activerecord
Questions have_many question_tags.
How can I get all questions that:
Here are the tables:
Questions
is_answered:boolean
vote_count:integer
QuestionTags
name:string
question_id:integer
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止的查询.它做#1和#2.我怎么能做#3?
Question.joins(:question_tags).where(question_tags: {name: "javascript"}, question: {is_answered: false})
Run Code Online (Sandbox Code Playgroud)
这看起来像是这个问题的重复。您想要的是where的字符串或数组语法。
Question.joins(:question_tags).where(question_tags: {name: "javascript"}, is_answered: false).where(["#{Question.table_name}.vote_count > ?", 2])
Run Code Online (Sandbox Code Playgroud)
更新为在最后的where子句中包含表名。
| 归档时间: |
|
| 查看次数: |
7328 次 |
| 最近记录: |