1

I have HABTM associations between two models but can only get find to return one level. I can return several levels with other associations but think I must be missing something with HABTM.

Controller/SchedulesController.php

$this->Schedule->find('first', array(
  'contain' => array(
    'Association' => array(
      'Schedule'
    )
  )
));

Model/Schedule.php

public $actsAs = array('Containable');
public $hasAndBelongToMany = array(
  'Association'
);

Model/Association.php

public $actsAs = array('Containable');
public $hasAndBelongsToMany = array(
  'Schedule'
);

At the moment I only get...

array(
  'Schedule' => array(
     ...
  ),
  'Association' => array(
    (int) 0 => array(
      ...
    'AssociationsSchedule' => array(
      ...
    )
  )
)

...but I would like Schedule -> Association -> Schedule

Boran
  • 31
  • 3

1 Answers1

-1

While contain() should work, the other option is to use the recursive option before the find like this:

$this->Schedule->recursive = 3; //2 might work, but I think you need 3 levels
$this->Schedule->find('first');

Its also worth mentioning that a similar question was asked here.

Community
  • 1
  • 1
ahjohnston25
  • 1,915
  • 15
  • 36