Search code examples
ruby-on-railsarel

How can I calculate with columns in AREL


In Rails I need to compare the value of one column with the difference of two other columns, i.e.

SELECT * from orders where paid < amount - bargain

How can I construct the condition with AREL?

Order.where(Order.arel_table[:paid].lt( ... ))

Solution

  • After trying around it is as simple as

    Order.where(Order.arel_table[:paid].lt(Order.arel_table[:amount] - Order.arel_table[:bargain]))