How to properly add brackets to SQL queries with 'or' and 'and' clauses by using Arel?

后端 未结 3 2074
遥遥无期
遥遥无期 2021-01-05 06:33

I am using Ruby on Rails 3.2.2 and I would like to generate the following SQL query:

SELECT `articles`.* FROM `articles` WHERE (`articles`.`user_id` = 1 OR `         


        
3条回答
  •  旧时难觅i
    2021-01-05 07:18

    I had the same problem. I was searching the web for some hours and finally found a method named grouping in Arel::FactoryMethods which simply adds brackets around an expression.

    You should wrap your groups with a arel_table.grouping(...) call.

提交回复
热议问题