$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]);
这是我的查询,我在表leads
中使用左连接表lead_status
。现在,我还想在同一个查询中使用左连接作为第三个表assigned_leads
。
我尝试将已加入的表leads
和lead_status
与assigned_leads
联系起来。我正在使用cakephp 3.x我怎样才能做到这一点?
答案 0 :(得分:1)
我已经使用左连接解决了这个问题,如下所示:
$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]);