【问题标题】:How to user two left joins in cakephp 3.x如何在 cakephp 3.x 中使用两个左连接
【发布时间】:2017-07-28 05:21:56
【问题描述】:
$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 使用左连接。

我已尝试将连接表 leadslead_statusassigned_leads 关联。我正在使用 cakephp 3.x 我该如何实现呢?

【问题讨论】:

    标签: php mysql cakephp cakephp-3.x


    【解决方案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]);
    

    【讨论】:

      猜你喜欢
      • 2015-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多