David
David

Reputation: 1

Convert aliased Mysql into cakePHP find statement

Please help me to convert this query into cakePHP find statement --

mysql> select auctions.id, auctions.price, products.target_price, (auctions.price / products.target_price) as target_ratio FROM auctions LEFT JOIN products ON auctions.product_id = products.id ORDER BY target_ratio DESC;

In particular, I've having difficulty getting this sections to work:

 (auctions.price / products.target_price) as target_ratio

Thanks!

Upvotes: 0

Views: 131

Answers (1)

deceze
deceze

Reputation: 521995

For the ratio part you should use Virtual Fields.
The join should be done automatically if your models have a belongsTo or hasOne relationship, otherwise you can join them manually.

Upvotes: 2

Related Questions