2012-07-09 40 views
0

如何在phpactiverecords中添加不相等的條件?phpactiverecords - 不等於

Code_reference::find('all', array('code' => $name), array('conditions' => 'id != '.$code_id)) 

回答

0

嘗試使用<>

Code_reference::find('all', array('code' => $name), array('conditions' => 'id <> '.$code_id)) 
+0

是它可以打印SQL查詢?這與我自己的代碼有相同的結果.. – clarkk 2012-07-09 10:35:42

0

在你的榜樣,第二$options陣列將被忽略。你必須自己合併它們,因此不能再使用緊湊的散列 -mode。

CodeReference::all(array('code = ? AND id != ?', $name, $code_id)); 

要打印SQL查詢,可以使用last_sql

CodeReference::table()->last_sql 

欲瞭解更多詳情,請參考官方的(但尚未laggy)文檔:

http://www.phpactiverecord.org/projects/main/wiki/Finders#conditions