Relational Query with through

Hi there,

I am about to test it my self but I would like to ask you if it is possible to do the following:





// FROM a Teacher Model

public function relations()

{

	// NOTE: you may need to adjust the relation name and the related

	// class name for the relations automatically generated below.

	return array(

		'sections'=>array(self::HAS_MANY, 'Section', 'teacherId'),

		'sessions'=>array(self::HAS_MANY, 'Session', 'sectionId', 'through'=>'sections'),

                // PUT ATTENTION ON THIS

		'students'=>array(self::MANY_MANY, 'Student', 'tbl_student_enrollment(studentId,sessionId)','through'=>'sessions' )

	);

}



Have you tried the above? Do you think is worth having it instead of creating a function that returns all related Students with a DAO command? Any feedback is highly appreciated (as usual)

The guide states the following

/Tommy

I read through that guide too… I will look in it… was curious

Thanks Tom

You can’t use MANY_MANY with through but you can get same functionality using it with HAS_ONE and HAS_MANY.

Thanks for answering, so, do I have to create a StudentEnrollment Model or can be directly accessed as Stated Above?

ie




// FROM a Teacher Model

public function relations()

{

        // NOTE: you may need to adjust the relation name and the related

        // class name for the relations automatically generated below.

        return array(

                'sections'=>array(self::HAS_MANY, 'Section', 'teacherId'),

                'sessions'=>array(self::HAS_MANY, 'Session', 'sectionId', 'through'=>'sections'),

                 'enrollments'=>array(self::HAS_MANY, 'StudentEnrollment', 'sessionId', 'through'=>'sessions'),

                'students'=>array(self::HAS_MANY, 'Student', 'studentId','through'=>'enrollments' )

        );

}




Edit: Was just curious, as I just realized that i can access students by the sessions relations

Congrats for this feature Samdark… very good