missing FROM-clause entry for table “Grupo” cakephp

前端 未结 2 677
[愿得一人]
[愿得一人] 2020-12-22 06:50

hi i have aproblem in my code, I want generate a list of user but this have a group and need just a group of user. the error say:

Error: SQLSTATE[42P

2条回答
  •  清歌不尽
    2020-12-22 07:33

    Link your models together using associations: CakePHP Associations

    Alternatively you can use custom sql-statemens using join e.g.:

    $db = $this->getDataSource();
    $result = $db->fetchAll(
                "SELECT Soya.id AS Soya__id, Soya.username AS Soya__username FROM public.users AS Soya 
                join Grupo on Grupo.id = Soya.groupo_id
                WHERE Grupo.categoria = ? AND Grupo.subcategoria = ?",
                array('Soya', 'Productor de Oleaginosas')
            );
    
    $this->set('oleaginosas', $result);
    

提交回复
热议问题