繁体   English   中英

如何在 cakephp 3.x 中使用两个左连接

[英]How to user two left joins in cakephp 3.x

$table = TableRegistry::get('Leads');
$query = $table->find('all')->leftJoinWith('LeadStatus')->contain(['Users', 'LeadStatus' =>
function ($q)
    {
    return $q->contain(['LeadBuckets', 'LeadBucketSubStatus'])->where(['LeadStatus.is_active' => 1]);
    }

])->where(['Leads.sub_agent_id' => $subAgentId]);

这是我的查询,我使用左连接从表lead_status获取表leads 现在,我还想在同一个查询中对第三个表assigned_leads使用左连接。

我曾尝试连接表的关联leadslead_statusassigned_leads 我正在使用 cakephp 3.x 我怎样才能做到这一点?

我已经使用左连接解决了这个问题,如下所示:

$query = $table->find('all')->leftJoinWith('LeadStatus')
          ->leftJoinWith('AssignedLeads')
          ->contain(['AssignedLeads'=>'Users','LeadStatus' => function($q)
               {
                  return $q->contain(['LeadBuckets', 'LeadBucketSubStatus'])
                     ->where(['LeadStatus.is_active' => 1]);
               }
               ])
          ->where(['Leads.sub_agent_id' => $subAgentId])
          ->where(['AssignedLeads.user_id IN' => $userId]);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM