Does CakePHP belong to several models?

I apologize in advance if this question was answered elsewhere; I searched high and low for an existing answer, but came out empty. Maybe I was looking for the wrong keywords.

I have three models: two (Student and Tutor) of which are related $hasManyto the general model (Purpose), which is related $belongsToto both other models. Exact models below ...

The student has many assignments ...

class Student extends AppModel {
    var $hasMany = array (
        'Appointment' => array (
            'foreignKey' => 'student_id'
        )
    );

A mentor has many purposes ...

class Tutor extends AppModel {
    var $hasMany = array (
        'Appointment' => array (
            "foreignKey" => 'tutor_id'
        )
    );

The assignment belongs to the student and teacher ...

class Appointment extends AppModel {
    var $belongsTo = array (
        'Student' => array (
            'foreignKey' => 'student_id'
        ),
        'Tutor' => array (
            'foreignKey' => 'tutor_id'
        )   
    );

(, "app/student/view/4" ) . Tutor (), Student. , $this->Student->query(), , .

$hasMany $belongsTo . CakePHP , , , - -?

+3
1

Containable. , Behavior, , , find, , .

, AppModel:

var $actsAs = array('Containable');

:

$this->Student->find('first', array(
    'conditions' => ...,
    'contain' => array('Appointment' => 'Tutor'),
    ...
));
+3

All Articles