Reputation: 251
$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]);
This is my query where I am using left join for table leads
from table lead_status
. Now, I also want to use left join for third table assigned_leads
in same query.
I have tried association of joined tables leads
and lead_status
with assigned_leads
. I am using cakephp 3.x How can I achieve this?
Upvotes: 1
Views: 516
Reputation: 251
I have solved this using left join as shown below:
$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]);
Upvotes: 1