$transaction_query = $this->Transaction->find('all',
[
'limit' => $countList,
'fields' => ['Transaction.client_id','Transaction.name','Transaction.created','Transaction.message_id','Transaction.credit'],
'conditions' => ['Transaction.id' => $client_id],
'AND' => ['Transaction.name !=' => 'Facturation']
]);
答案 0 :(得分:13)
您的条件必须为['Transaction.id' => $client_id, 'Transaction.name !=' => 'Facturation']
。 conditions
数组的多个条件被解释为' AND'条件。
所以你的查询看起来像: -
$transaction_query = $this->Transaction->find('all',
[
'limit' => $countList,
'fields' => [
'Transaction.client_id',
'Transaction.name',
'Transaction.created',
'Transaction.message_id',
'Transaction.credit'
],
'conditions' => [
'Transaction.id' => $client_id,
'Transaction.name !=' => 'Facturation'
]
]
);
如果您有重复的条件数组键,则只需按and
索引;在您的示例中并非如此,因为您有Transaction.id
和Transaction.name !=
。无论如何,and
索引需要是conditions
数组中的索引,而不是兄弟。
答案 1 :(得分:3)
$this->Transaction->find( 'all', array(
'limit' => $countList,
'fields' => ['Transaction.client_id','Transaction.name','Transaction.created','Transaction.message_id','Transaction.credit'],
'conditions' => array("not" => array ( 'Transaction.id' => $client_id)),
'AND' => array('not' => ('Transaction.name ' => 'Facturation')));
如果您希望该名称不应该是其中任何一个,那么您应该按如下方式编写查询:
$this->Transaction->find('all', array('conditions' => array('NOT' => array('Transaction.name' => array('a','aa','aaa')))));