10

can you see the error guys ? my AND conditions is ignored! I'm getting so frustrated with those arrays..

 $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']
                ]);
1
  • 1
    Can you please provide details on the misbehaviour you encounter? Commented Jun 11, 2015 at 12:33

2 Answers 2

17

Your conditions need to be ['Transaction.id' => $client_id, 'Transaction.name !=' => 'Facturation']. Multiple conditions of the conditions array are interpreted as 'AND' conditions.

So your query would look like:-

$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'
        ]
    ]
);

You only need to index by and if you have duplicate condition array keys; this is not the case in your example as you have Transaction.id and Transaction.name !=. Regardless, the and index would need to be an index inside the conditions array, not a sibling.

4
 $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')));

In case if you want that name should not be any one of them then you should write query as follows:

$this->Transaction->find('all', array('conditions' => array('NOT' => array('Transaction.name' => array('a','aa','aaa')))));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.