Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding records where one attribute is greater than another

I want to find any product that has a higher ip_solid than ip_liquid.

I am trying to do the following:

Product.where("ip_solid > ?", :ip_liquid).count

However, it seems that :ip_liquid is not being read out from each object, and is probably evaluating to 0 or nil. Is something like this even possible?

like image 437
Abram Avatar asked Sep 26 '22 08:09

Abram


1 Answers

Product.where("ip_solid > ip_liquid").count should do it as long as ip_liquid is a field in the database and not a method on your model

like image 150
nbermudezs Avatar answered Sep 28 '22 04:09

nbermudezs