如何HasAndBelongsToMany
在 CakePHP 2.8 中解除绑定关系?我有这个模型连接到任务模型(N:M 关系)。
class Date extends AppModel
{
public $name = 'Date';
public $displayField = 'rdate';
public $actsAs = array('Containable');
public $hasAndBelongsToMany = array('Task' => array('className' => 'Task'));
public function getCurrentDate()
{
return $this->find('first',
array(
'conditions' => array(
'Date.rdate' => date('Y-m-d')
)
)
);
}
}
我想在getCurrentDate()
函数中解绑这种关系,但是$this->recursive = -1;
在这个函数中也不行find()
。我只需要模型中的一条记录,Date
但 find 返回与该模型相关的所有任务。
编辑#1:即使在运行中解除绑定模型也不起作用:
$this->unbindModel(
array('hasAndBelongsToMany' => array('Task'))
);
仍然返回关联的模型数据。