将别名的Mysql转换为cakePHP查找语句

时间:2010-11-10 01:54:34

标签: mysql cakephp

请帮我将此查询转换为cakePHP查找语句 -

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;

特别是,我很难让这些部分发挥作用:

 (auctions.price / products.target_price) as target_ratio

谢谢!

1 个答案:

答案 0 :(得分:2)

对于比例部分,您应该使用Virtual Fields 如果您的模型具有belongsTo或hasOne关系,则应自动完成连接,否则您可以join them manually