Using more or less than a Rails Active Record query

Questions have_many question_tags .

How can I get all the questions that are:

  • Enter question_tag with the name "javascript"
  • Not responding
  • Are there more than 2 "vote_count"?

Here are the tables:

Questions is_answered:boolean vote_count:integer QuestionTags name:string question_id:integer 

This is the request that I have so far. This is number 1 and number 2. How can I do # 3?

 Question.joins(:question_tags).where(question_tags: {name: "javascript"}, question: {is_answered: false}) 
+5
source share
1 answer

This seems like a duplicate of this question . You want to use string or array syntax for where .

 Question.joins(:question_tags).where(question_tags: {name: "javascript"}, is_answered: false).where(["#{Question.table_name}.vote_count > ?", 2]) 

Updated to include table name in last where clause.

+3
source

Source: https://habr.com/ru/post/1210119/


All Articles