Arel `between` with other columns as a range

It seems that the Arel predicate Betweencan only be used with ranges, e.g.

between(1.day.ago.time..Time.current)

Does anyone know a way to use it with other columns? how

between(table[:since]..table[:till]) 

(the latter will not work, but it shows the idea). In the end i want

column BETWEEN table.since AND table.till
+4
source share
1 answer

To generate table.field BETWEEN another_table.from AND another_table.to, use this code:

Arel::Nodes::Between.new(
  table[:field],
  Arel::Nodes::And.new(
    [
      another_table[:from],
      another_table[:to]
    ]
  )
)

In my case, I put this code in the .and()isl method .

+2
source

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


All Articles