我在CakePHP3工作,我读了官方书,但没有找到。我想使用join显示其他表的列。我有这段代码:
$id = $this->Auth->User('idUsuarios');
$lastquery = TableRegistry::get('Apuestas');
$query = $lastquery->find()
->join([
'Juego' => [
'table' => 'juego',
'type' => 'LEFT',
'conditions' => 'Apuestas.juego_idJuego = Juego.idJuego'
]])
->where(['usuarios_idUsuarios' => $id])
->order(['fecha' => 'ASC'])
->limit(1);
$this->set(compact('query'));
但它没有显示任何加入表。
答案 0 :(得分:1)
看一下本书的这一部分。
http://book.cakephp.org/3.0/en/orm/associations.html
选择最合适的关联
让我展示你的榜样:
稍后,按$ id显示特定地点
$spot = $this -> Spots -> find()->where(['Spots.id' => $id])-> contain(['Provinces' => ['Communities' => ['Countries']]])->first();
现在我可以在视野中打电话,例如$spot -> province -> name
或$spot -> country -> name