2017-07-28 121 views
1
$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的左連接。兩個左CakePHP中3.X

我試過聯合表leadslead_statusassigned_leads。我正在使用cakephp 3.x我怎樣才能做到這一點?

回答

0

我已經解決了這個使用LEFT JOIN,如下圖所示:

$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]);