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

如何在cakephp 3.x中使用两个左连接,php,mysql,cakephp,cakephp-3.x,Php,Mysql,Cakephp,Cakephp 3.x,这是我的查询,我正在使用表lead\u status中的表lead的左联接。现在,我还想对同一查询中的第三个表assigned\u leads使用left join 我已尝试将已联接的表潜在客户和潜在客户状态与已分配的潜在客户关联起来。我正在使用cakephp 3.x如何实现这一点?我已使用左连接解决了此问题,如下所示: $table = TableRegistry::get('Leads'); $query = $table->find('all')->leftJoinWith('

这是我的查询,我正在使用表
lead\u status
中的表
lead
的左联接。现在,我还想对同一查询中的第三个表
assigned\u leads
使用left join


我已尝试将已联接的表
潜在客户
潜在客户状态
已分配的潜在客户
关联起来。我正在使用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]);
$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]);