0

I have a getter method in my Rails model like this

def abc
  self.a * self.b * self.c
end

Is there any way I can use this method inside my sql query like this.

Model.where("abc >=?", 10)
Nidhin S G
  • 1,685
  • 2
  • 15
  • 45

1 Answers1

4

Are those a, b and c fields on db? In that case you could do

Model.where("a * b * c >= ?", 10)

Otherwise, if nor abc neither a, b and c are fields on db I fear you can't do all with a query and I'd use a select

Model.all.select { |o| o.abc >= 10 }
Ursus
  • 29,643
  • 3
  • 33
  • 50