Ralf Hohoff

SQL mit CakePHP und der Bedingung NOT IN

$this->set('agents',$this->Contract->User->find('list',array(
			'fields' => array('User.id','User.username'),
			'conditions' => array(
						'User.active =' => '1',
						'NOT' => array(
							'User.username' => array('admin',$this->Auth->user('username'))
							))
			))
);

Which produces the following:

SELECT `User`.`id`, `User`.`username` FROM `users` AS `User` WHERE  `User`.`active` = 1 AND NOT (`User`.`username` IN ('admin', 'user'))

Quelle: http://cakebaker.42dh.com/2007/04/26/how-to-use-not-in-in-a-condition/

Ganz schön komfortabel aber auch tricky, wenn man diesen Weg nicht kennt 😉

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert