【问题标题】:Does anyone know how Group By can work with paginate in CakePHP?有谁知道 Group By 如何在 CakePHP 中使用分页功能?
【发布时间】:2011-11-17 06:34:32
【问题描述】:

我有以下代码段,我想在其中按 Release.id 对所有内容进行分组,因为我得到了很多重复项。即使我有一个 DISTINCT,它也会被完全忽略。

有人可以指导我正确的方向吗?

$this->Release->recursive = 0;
    $this->paginate['Release']['joins'] =
                   array(
                    array(
                        'table' => 'game_potential_amazon_matches',
                        'alias' => 'PotentialAmazonMatch',
                        'type' => 'inner',
                        'conditions' =>
                        array(
                            'PotentialAmazonMatch.release_id = Release.id'
                            ),'fields' => array('DISTINCT Release.id')
                           )
                    );
    $this->set('releases', $this->paginate('Release'));






RELEASE TABLE
id
name
asin


MATCHES TABLE
date
asin
release_id

matches 表与 Release 表是一对多的关系。我只想要一个版本。

【问题讨论】:

  • 这似乎是要连接的表的代码sn-p。你能传递这个连接的表的代码吗?

标签: php cakephp cakephp-1.3 cakephp-1.2


【解决方案1】:

您现在正在定义'fields' => array('DISTINCT Release.id') 在数组中
$this->paginate['Release']['joins'].

尽量放在$this->paginate['Release'].中的条件之后

【讨论】:

  • 我试过这个:$this->paginate['Release']['conditions'] = array('fields' => array('DISTINCT Release.id'));
  • 不,试试$this->paginate['Release']['fields'] = array('DISTINCT Release.id');
猜你喜欢
  • 1970-01-01
  • 2013-03-02
  • 1970-01-01
  • 2020-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-24
相关资源
最近更新 更多