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

this query using left join table leads table lead_status. now, want use left join third table assigned_leads in same query.

i have tried association of joined tables leads , lead_status assigned_leads. using cakephp 3.x how can achieve this?

i have solved using left join 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]); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -