2012-12-07 8 views
0

的比較值,我使用查詢表FuelPHP 1.3的模型時有問題。 條目表有三列('id','status','current','max')。如何在兩列FuelPHP

$result = Model_Entry::query() 
    ->where('status', 1) 
    ->where('count_current', '>=', 'count_max'); 

我想使用'where'方法的第三個參數作爲列名,但它在生成的查詢中作爲值處理。

SELECT * FROM `entries` AS `t0` WHERE `t0`.`status` = 1 AND `t0`.`count_current` >= 'count_max' 

我的目標

SELECT * FROM `entries` AS `t0` WHERE `t0`.`status` = 1 AND `t0`.`count_current` >= `t0`.`count_max` 

任何幫助,將不勝感激。

回答

2

達到你想要什麼,你必須使用DB::expr()

所以,你的代碼將是:

$result = Model_Entry::query() 
    ->where('status', 1) 
    ->where('count_current', '>=', DB::expr('count_max'));