如何在 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]);
这是我的查询,我使用 table leads
来自 table lead_status
的左连接。现在,我还想在同一查询中对第三个 table assigned_leads
使用左连接。
我已经尝试将加入的 tables leads
和 lead_status
与 assigned_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]);
$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]);
这是我的查询,我使用 table leads
来自 table lead_status
的左连接。现在,我还想在同一查询中对第三个 table assigned_leads
使用左连接。
我已经尝试将加入的 tables leads
和 lead_status
与 assigned_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]);