Reputation: 1695
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)
Upvotes: 0
Views: 105
Reputation: 30071
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 }
Upvotes: 4