Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP find WHERE NOT EQUAL

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']
                ]);
like image 658
181mdz Avatar asked Jun 11 '15 12:06

181mdz


1 Answers

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.

like image 120
drmonkeyninja Avatar answered Sep 16 '22 15:09

drmonkeyninja