Complex Arel conditions with AND and OR
I have a question about creating multiple conditions with AND
and OR
in one of the priority operations.
So, I need to generate the following SQL line to navigate to the method where
:
where("NOT ((assignments.to IS NOT NULL AND assignments.to < :start_date) OR assignments.from > :end_date)", start_date: date.at_beginning_of_week, end_date: date.at_end_of_week)
I rewrote it with Arel:
table = Assignment.arel_table
where(
table[:from].gt(date.at_end_of_week).
or(
table[:to].not_eq(nil).and(table[:to].lt(date.at_end_of_week))
).not
)
But Arel does not place parentheses around the c clause AND
, and as a result that clause selects the wrong data. How can I put the brackets in this state?
+3
source to share