I am trying to figure out which relationship type should I use to relate the following:
We have a classroom that has a teacher and students.
Students and teacher belongsTo classroom. But what about the other way around?
Can I use the following in the Classroom model:
var $hasMany = array('Students');
var $hasOne = array('Teacher');
Thanks.
Depends on how you want to retrieve and/or model the data.
Assuming your
Classroomswill only have oneTeacher, orTeacherswill only have oneClassroom, you can even get away with makingClassrooma field ofTeacher.But we’ll assume you want to keep it all abstracted from each other. In this case, your models would look something like this: