Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // See http://stackoverflow.com/questions/13826474/cakephp-containable-with-habtm
- Controller::loadModel('Student');
- Controller::loadModel('Course');
- Controller::loadModel('CoursesStudent');
- $this->Student->bindModel(
- array('hasAndBelongsToMany' => array(
- 'Course'
- ))
- );
- $this->Course->bindModel(
- array('belongsTo' => array(
- 'Teacher'
- )),
- array('hasAndBelongsToMany' => array(
- 'Student'
- ))
- );
- $this->CoursesStudent->bindModel(
- array('belongsTo' => array(
- 'Course',
- 'Student'
- ))
- );
- $this->request->data = $this->Student->CoursesStudent->find('all', array(
- 'recursive' => 2,
- 'conditions' => array(
- 'CoursesStudent.is_approved' => null,
- 'Student.grade' => 9
- ),
- 'contain' => array(
- 'CoursesStudent',
- 'Course' => array(
- 'Teacher' => array(
- 'fields' => array(
- 'Teacher.id',
- 'Teacher.first_name',
- 'Teacher.last_name'
- )
- )
- ),
- 'Student'
- )
- ));
- pr($this->request->data);
- exit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement