Active record order_by the result of multiplying two fields |
Hi all,
I have the following active record query and it's working fine all except for the ordering. The query retrieves construction projects from one table and gets the minimum price by doing a select_min on the project units table and thus establishing the 'from' price for each project. Just to make things interesting, different projects have different base currencies, so we retrieve the exchange rate as part of the query. The problem i'm having is that i can't get it to order correctly by price. The strange thing is that it kinda works, but there are a few results misplaced. It's sorting about 80 percent fine with a few that just don't get sorted correctly whatever i do. If we want to order correctly, we have to multiply the from price by the exchange rate and order on the result. So basically we are ordering on the calculated result of two fields multiplied together. I don't know if this is a syntax issue here or if it may have something to do with the group_by statement. I suspect it could be the latter because when I remove the exchange rate multiplier and just select projects of the same base currency, it is still sorting badly. Anyway, here's the code: Code: function getProjects() |
Messages In This Thread |
Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 04:24 PM
RE: Active record order_by the result of multiplying two fields - by twpmarketing - 11-18-2014, 04:38 PM
RE: Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 04:45 PM
RE: Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 04:54 PM
RE: Active record order_by the result of multiplying two fields - by bclinton - 11-18-2014, 05:13 PM
RE: Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 05:22 PM
RE: Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 06:28 PM
RE: Active record order_by the result of multiplying two fields - by bclinton - 11-18-2014, 06:33 PM
RE: Active record order_by the result of multiplying two fields - by andycansdale - 11-18-2014, 06:39 PM
|