Cakephp复杂找到"NOT IN"

use*_*210 5 cakephp find notin

我有两个名为calendar_colour和user的表,

calendar_colour
(
   colour_id int primary key,
   colour varchar(15)
)


user
(
   id int primary key,
   name varchar(30),
   color int,
   foreign key(color) references calendar_colour(colour_id)
)
Run Code Online (Sandbox Code Playgroud)

在用户的添加功能中,我必须从下拉框中选择一种颜色.但我想使用以前用户尚未采用的颜色填充下拉列表.我尝试使用find命令,但似乎是错误的.

$curColours = $this->EventType->query('select color from event_types');

$this->set('colours', $this->EventType->CalendarColour->find('list',array('conditions'=>array('NOT',array('CalendarColour.colour_id' => $curColours)))));
Run Code Online (Sandbox Code Playgroud)

我使用数组$colours填充下拉框.编写查找命令以找到任何用户未使用的颜色的正确方法是什么.

谢谢.

Ari*_*aan 13

你几乎拥有它:

$this->EventType->CalendarColour->find('list', array(
  'conditions' => array(
    'NOT' => array( // There's your problem! :)
      'CalendarColour.colour_id' => $curColours
    )
  )
));
Run Code Online (Sandbox Code Playgroud)