# Convert cakephp2 join to 3

**URL:** <https://discourse.cakephp.org/t/convert-cakephp2-join-to-3/454>\
**Category:** Uncategorized\
**Created:** [June 3, 2016, 1:52pm UTC](https://discourse.cakephp.org/t/convert-cakephp2-join-to-3/454 "2016-06-03T13:52:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 3, 2016, 1:52pm UTC](https://discourse.cakephp.org/t/convert-cakephp2-join-to-3/454/1 "2016-06-03T13:52:43Z")

</div>

Hi,

What is the most effective way to convert cakephp2 join to cakephp3 ? I have the models setup but I dont know what the best way is even after reading

[http://book.cakephp.org/3.0/en/orm/query-builder.html](http://book.cakephp.org/3.0/en/orm/query-builder.html)

```
    $joins = array(
        array('table' => 'lessons_students',
            'alias' => 'LessonsStudent',
            'type' => 'LEFT',
            'conditions' => array(
            'Lesson.id = LessonsStudent.lesson_id',
             )
             ),
            
            array('table' => 'students',
            'alias' => 'Student',
            'type' => 'LEFT',
            'conditions' => array(
            'LessonsStudent.student_id=Student.id',
             )
             ),
             array('table' => 'subjects',
                    'alias' => 'Subject',
                    'type' => 'LEFT',
                    'conditions' => array(
                    'Lesson.subject_id=Subject.id',
             )
             ),
             array(
		'table' => 'tutors',
		'alias' => 'Tutor',
		'type' => 'LEFT',
		'conditions' => array(
		'Lesson.tutor_id = Tutor.id'
	)
	)       
        );
        
     
   
   
   
   
    $fieldoptions = array( 'Lesson.lesson_date', 'Lesson.start_time', 'Lesson.end_time', 'Lesson.id','Lesson.lesson_inactive',
               'Lesson.forefit','Lesson.tutor_id','Lesson.makeup_lesson_expired','Student.id',
             );
    
     
       // get all lessons on the day
      $condionoptions = array('Lesson.lesson_inactive' => 0,'Lesson.makeup_lesson' => 0,'Lesson.forefit' => 0,
          'Lesson.makeup_lesson_expired' => false, 'Lesson.lesson_date' => $lessonStartDate, 'Student.id' => $studentId,
                  );
      
      $orderoptions =array('Lesson.start_time'=> 'ASC');             
   

  $lessons=$this->find('all',array(
	 'conditions'=> $condionoptions,
          'joins'=>$joins,
           'fields'=>$fieldoptions,
         'recursive' =>-1,
            'order'=> $orderoptions,
          
           ));
```

---

<div class="post-metadata">

**Author:** ![alysson\_azevedo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/alysson_azevedo/32/194_2.png) [@alysson\_azevedo](https://discourse.cakephp.org/u/alysson_azevedo)\
**Post date:** [June 3, 2016, 2:26pm UTC](https://discourse.cakephp.org/t/convert-cakephp2-join-to-3/454/2 "2016-06-03T14:26:45Z")

</div>

In the LessionsTable, set a [BelongsToMany](http://book.cakephp.org/3.0/en/orm/associations.html#belongstomany-associations) associantion between Lessons and Studants, and a [BelongsTo](http://book.cakephp.org/3.0/en/orm/associations.html#belongsto-associations) associantion between Lesson and Subjects and Lesson and Tutors.

Later you use `contain` to [retrieve the associations](http://book.cakephp.org/3.0/en/orm/retrieving-data-and-resultsets.html#retrieving-associated-data)

---

<div class="post-metadata">

**Author:** ![jagguy](https://avatars.discourse-cdn.com/v4/letter/j/b487fb/32.png) [@jagguy](https://discourse.cakephp.org/u/jagguy)\
**Post date:** [June 4, 2016, 3:31am UTC](https://discourse.cakephp.org/t/convert-cakephp2-join-to-3/454/3 "2016-06-04T03:31:51Z")

</div>

yes I know this but my question is how to write the join I gave in cakephp3
