2014-03-25 35 views
-1

Cake正在逃避Contract.start_dateContract.end_date,導致查詢無效。cakePHP在BETWEEN條件下將字段名作爲字符串轉義

$this -> Contract -> find('all', array(
    'fields' => array(..), 
    'conditions' => array(
    'NOW() BETWEEN ? AND ?' => array(
     'Contract.start_date', 
     'Contract.end_date' 
    ) 
    ) 
)); 

的問題是執行的查詢是

SELECT 
    <fields> AS Monthly 
FROM 
    `contracts` AS `Contract` 
WHERE 
    NOW() BETWEEN 'Contract.start_date' AND 'Contract.end_date' 
#/* field names are escaped and treated as strings */ 

回答

2

這是因爲查詢參數是值(參數),而不是場。你不能使用?標記替換字段名稱,因爲正如您發現的那樣,它們被引用,就好像它們是字符串值。 (數據庫和表名也是如此,這是我之前遇到的問題,因此現在也知道您的問題的答案。)

在這種情況下,您只需簡單地使用'NOW() BETWEEN Contract.start_date AND Contract.end_date'

相關問題