2016-07-19 5 views
2

Wie wird die HasAndBelongsToMany Beziehung in CakePHP 2.8 gelöst? Ich habe dieses Modell, das mit Aufgabenmodell verbunden ist (N: M-Beziehung).Bindung von HasAndBelongsToMany in CakePHP 2 löst das Modell nicht

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') 
       ) 
      ) 
     ); 
    } 

} 

Ich mag würde in getCurrentDate() Funktion dieser Beziehung lösen, aber $this->recursive = -1; in dieser Funktion noch in find() funktioniert nicht. Ich brauche nur einen Datensatz von Date Modell, aber finden Sie alle Aufgaben in Bezug auf dieses Modell zurückgibt.

Edit # 1: Selbst unbinding Modell im Fluge nicht funktioniert:

$this->unbindModel(
    array('hasAndBelongsToMany' => array('Task')) 
); 

noch gibt zugehörige Modelldaten.

Antwort