Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arel syntax for ( this AND this) OR ( this AND this)

how would I do this in Arel ( this AND this) OR ( this AND this)

Context is rails 3.0.7

like image 792
pixelearth Avatar asked Dec 16 '22 00:12

pixelearth


1 Answers

Mike's answer was basically what you're looking for

class Model < ActiveRecord::Base
  def self.this_or_that(a1, a2, a3, a4)
    t = Model.arel_table
    q1 = t[:a].eq(a1).and(t[:b].eq(a2))
    q2 = t[:c].eq(a3).and(t[:d].eq(a4))
    where(q1.or(q2))
  end
end

some slides I put together on Arel

like image 94
Philip C Avatar answered Dec 31 '22 02:12

Philip C