I want to join between the two other tables in current controller and insert result in current controller table. This is my code but does'nt work:
class UesrsController extends AppController {
public function addRoom() {
$rooms = TableRegistry::get("Rooms");
$row = $rooms
->find('list', array('fields' => 'id'))
->join([
'table' => 'dormitories',
'conditions' => ['dormitories.id=rooms.dormitory_id']
])
->where(['dormitories.name =' => 'aaa'])
;
$this->set('row', $row);
return $rooms;
}
}
In above code, I want to join between dormitories and rooms and save result to users table.
You could try something like this:
And I think you need to add a type of join. But I can be wrong on that one.
class UesrsController extends AppController {
public function addRoom() {
$rooms = TableRegistry::get("Rooms");
$rooms
->find('list', array('fields' => 'id'))
->join([
'table' => 'dormitories',
'type' => 'LEFT',
'conditions' => ['dormitories.id=rooms.dormitory_id',
'dormitories.name =' => 'aaa'
]
])
;
}
}