lx00st
lx00st

Reputation: 1596

Arel `between` with other columns as range

It seems that Arel's Between predicate can be used with ranges only, eg

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

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

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

(the last will not work but it shows an idea). In the end I want

column BETWEEN table.since AND table.till

Upvotes: 4

Views: 2105

Answers (1)

Stepan Zakharov
Stepan Zakharov

Reputation: 420

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

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

In my case I placed this code into .and() arel method.

Upvotes: 2

Related Questions