Update: A search of the forum finds a couple of posts where folks are actually recommending drilling down through _joinData or _matchingData. Not only is this behavior undocumented (I’m not finding it in the 5.x docs), but it’s bad mojo to depend upon private variable access to implement functionality. I’m having a hard time believing this is the accepted answer.
Original question: I have a simple test setup with two tables and an association table:
CREATE TABLE
courses(
course_idint(11) NOT NULL,
course_namevarchar(10) DEFAULT NULL,
PRIMARY KEY (course_id)
)
CREATE TABLEstudents(
student_idint(11) NOT NULL,
student_namevarchar(10) NOT NULL,
PRIMARY KEY (student_id)
)
CREATE TABLEcourses_students(
idmediumint(8) unsigned NOT NULL AUTO_INCREMENT,
gradeint(11) NOT NULL,
course_idint(11) NOT NULL,
student_idint(11) NOT NULL,
PRIMARY KEY (id),
KEYfk_course(course_id),
KEYfk_student(student_id),
CONSTRAINTfk_courseFOREIGN KEY (course_id) REFERENCEScourses(course _id),
CONSTRAINTfk_studentFOREIGN KEY (student_id) REFERENCESstudents(stu dent_id)
)
I used bake to generate all code.
If I use
$query = $this->Students->find(‘all’, contain:[‘Courses’]);
the associated field “grade” is buried in a private attribute called _joinData. If I use
find()->matching()
, it’s buried in _matchingData. How do I access the data field from the association without going through either _joinData or _matchingData?