2010-11-10 20 views
0

請幫我轉換這個查詢到CakePHP的發現聲明 -別名轉換成mysql的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 

謝謝!

回答

2

對於比例部分,您應該使用Virtual Fields
如果您的模型擁有belongsTo或hasOne關係,則應該自動完成連接,否則您可以join them manually

+0

謝謝。好的,加入是由蛋糕自動完成的。 – David 2010-11-11 01:11:09

+0

我添加了 var $ virtualFields = array('target_ratio'=>'(auctions.price/products.target_price)'; – David 2010-11-11 01:13:30

+0

(我不喜歡在輸入時自動提交) - 我將代碼添加到頂端但是當我做一個Cake Find的時候,這個字段還沒有出現,是否有某種方法可以從查找中調用?Cakebook在這一點上還不清楚,它聽起來像我所要做的一切是添加該行,它只會出現在查詢結果中。這是行不通的。 – David 2010-11-11 01:14:55