【问题标题】:CakePHP find is not returing all the fields when using a join使用连接时,CakePHP 查找未返回所有字段
【发布时间】:2023-03-10 00:47:01
【问题描述】:

您好,我正在尝试在我的报告模型中加入 2 个表格报告和报告结果

$report = $this->find('first', array(
                'joins' => array(
                    array(
                        'table'      => 'report_results',
                        'alias'      => 'rr',
                        'type'       => 'INNER',
                        'fields'     => array(
                            "Report.*", "rr.*"
                        ),
                        'conditions' => array(
                            "rr.report_id = {$this->alias}.id",
                            "{$this->alias}.status" => Report::STATUS_GENERATED,
                            "{$this->alias}.start_day = CURDATE() - INTERVAL 3 DAY",
                        )
                    )
                ),

                'order' => array("rr.total DESC")
            ));

我的问题是只返回报告表字段。它似乎没有将字段部分纳入查询。最初我没有指定字段,但是当我指定它们或尝试限制返回的字段时,它仍然会返回整个集合。

谁能指出我可能遗漏或做错了什么?

【问题讨论】:

    标签: cakephp


    【解决方案1】:

    典型!在我发布问题之前,我花了很长时间环顾四周,我一发布就找到了答案。

    因此,通过将字段移出加入它可以工作

    $report = $this->find('first', array(
                    'joins' => array(
                        array(
                            'table'      => 'report_results',
                            'alias'      => 'rr',
                            'type'       => 'INNER',
    
                            'conditions' => array(
                                "rr.report_id = {$this->alias}.id",
                                "{$this->alias}.status" => Report::STATUS_GENERATED,
                                "{$this->alias}.start_day = CURDATE() - INTERVAL 3 DAY",
                            )
                        )
                    ),
    
                    'fields'     => array(
                                "Report.*", "rr.*"
                            )
    
                    'order' => array("rr.total DESC")
                ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-01
      • 1970-01-01
      • 2022-01-10
      • 2018-05-07
      • 1970-01-01
      相关资源
      最近更新 更多