我有table1'lead',我想在两个不同的表上使用两个连接以及内部应用,例如'lead_status'和'assigned_leads'。我对cakephp 3.x概念非常新,因此无法理解如何使用多个连接编写查询。请建议我如何编写该查询。提前谢谢。
这是我在领导表模型中所做的关联:
class LeadsTable extends Table
{
public function initialize(array $config)
{
$this->hasMany('LeadStatus', [
'className' => 'LeadStatus',
'foreignKey' => 'lead_id',
'propertyName' => 'LeadStatus'
]);
$this->hasMany('AssignedLeads', [
'className' => 'AssignedLeads',
'foreignKey' => 'lead_id',
'propertyName' => 'AssignedLeads'
]);
}
}
我正在使用cake php 3.x.请建议如何编写多个连接。
我试过这样但没有给出适当的条件数据
$query = $table->find('all')->leftJoinWith('LeadStatus')->innerJoinWith('AssignedLeads')->contain(['LeadStatus' => function($q) {
return $q->contain(['LeadBuckets', 'LeadBucketSubStatus'])
->where(['LeadStatus.is_active' => 1]);
}],['AssignedLeads' => function($s) {
return $s->contain(['Users'])
->where(['AssignedLeads.is_active' => 1]);
}])->where(['Leads.sub_agent_id' => $subAgentId,
]);