Absolute value in AREL (rails)

I need to do some absolute values ​​in AREL. Basically you need to understand how to execute this line (in relational algebra) with ARel:

Suppose P is a table with columns value1 and value2:

Project((|p.value1 - 10| + |p.value2 - 10|) as match) P

      

Not sure if this is possible with AREL.

Thanks in advance!

+3


source to share


1 answer


You'd better do this SQL:



class Project < ActiveRecord::Base
  def self.abs_values
    connection.select_values('SELECT abs(value1-10), abs(value2-10) FROM projects')
  end
end

      

+1


source







All Articles