duanbodai5166
2017-02-08 03:31
浏览 12
已采纳

如何正确执行CakePHP 3中的LEFT连接?

I have been attempting to use CakePHP 3's query builder format in order to learn how to better use it. However, at the moment I cannot seem to get a left join working.

There is information available in both tables that I would like to collect in the result:

    $query = $this->find()->where(['userID' => $UID])->hydrate(false)->join([
        'table' => 'authgroups',
        'alias' => 'a',
        'type' => 'LEFT',
        'conditions' => 'a.id = userGroup'
    ]);

    return $query->toArray();

If I'm reading the CookBook correctly, this should work - however, it is being used in a model which differs from the example, and the result only returns from that table, seemingly ignoring the join. Do I need to execute this in the controller instead?

图片转代码服务由CSDN问答提供 功能建议

我一直在尝试使用CakePHP 3的查询构建器格式,以便学习如何更好地使用它。 但是,目前我似乎无法让左连接工作。

我希望在结果中收集两个表中的信息:

  $ query = $ this->  find() - > where(['userID'=> $ UID]) - > hydrate(false) - > join([
'table'=>'authgroups',
'alias'=  >'a',
'type'=>'LEFT',
'条件'=>'a.id = userGroup'
]); 
 
返回$ query-> toArray(  ); 
   
 
 

如果我正确读取CookBook,这应该可行 - 但是,它在一个与示例不同的模型中使用,结果 只返回该表,似乎忽略了连接。 我需要在控制器中执行此操作吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题