i have two models. Teacher and Subject joined by HABTM defined both ways. A teacher can teach many subjects and a subject can be taught by many teachers.my join table is subjects_teachers and have fields id,teacher_id and subject_id.
Fetching Teacher data from its model, i expect all teachers and their respective subjects , Fetching Subject data from its model i expect to also see the teachers teaching that particular subject
problem on both instances, the associated model returns the correct number of records but the data is absent. i see [maximum depth reached] when i display the respective arrays.
I removed the id field from the join table and that fixed only the Teacher model.The Subject model still has the problem.
i just need to know what [maximum depth reached] means and why removing the id filed from the join table fixed the Teacher problem but not Subject.
also if its important i should mention that my Teacher model primary key field doesnt follow convention SUBJECT model
public $hasAndBelongsToMany = array( 'Teacher' => array( 'className' => 'Teacher', 'joinTable' => 'subjects_teachers', 'foreignKey' => 'subject_id', 'associationForeignKey' => 'teacher_id', 'unique' => 'keepExisting' ) );
Teacher Model
public $hasAndBelongsToMany = array( 'Subject' => array( 'className' => 'Subject', 'joinTable' => 'subjects_teachers', 'foreignKey' => 'teacher_id', 'associationForeignKey' => 'subject_id', 'unique' => 'keepExisting' ) );
Results from subject
array( (int) 0 => array( 'Subject' => array( 'id' => '1', 'subject_code' => '121', 'subject_name' => 'Mathematics', 'compulsory' => true ), 'Teacher' => array( (int) 0 => array( [maximum depth reached] ), (int) 1 => array( [maximum depth reached] ), (int) 2 => array( [maximum depth reached] ) ) ),
Results from Teacher before removin id field
array( 'Teacher' => array( 'teacher_id' => '6', 'first_name' => 'George', ), 'Subject' => array( (int) 0 => array( 'id' => '1', 'subject_code' => '121', 'subject_name' => 'Mathematics', 'compulsory' => true, 'SubjectsTeacher' => array( [maximum depth reached] ) )
Results after removing id field
'Subject' => array( (int) 0 => array( 'id' => '1', 'subject_code' => '121', 'subject_name' => 'Mathematics', 'compulsory' => true ),