CakePHP在派生字段中分页条件 [英] CakePHP paginate conditions in derived fields

查看:144
本文介绍了CakePHP在派生字段中分页条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编制一份游戏列表,其中的运动是一个选定的运动。
相关性如下:
游戏属于竞赛BelongsTo团队BelongsTo sport
我想做的是显示所有游戏,其中球队sport_id = 1.
以下' t work:

i would like to paginate a list of games, where the sport is a chosen sport. the relatition is as followed: Game BelongsTo Competition BelongsTo Team BelongsTo sport What i would like to do is show all games where the teams sport_id = 1. The following doesn't work:

        $this->paginate = array('limit' => 30, 'page' => 1, 
    'conditions' => array('Competition.Team.sport_id' => '1'),
        'contain' => array('Competition', 'Competition.Team',
        'Gamefield', 'Changingroom', 'ChangingroomAway', 'Gametype'),
    'order'=>array('game_date'=>'asc'),         
    );  

任何人都可以帮我解决这个问题吗?

Can anyone help me with this one?

推荐答案

我找到了我的解决方案:

I've found my solution:

    var $paginate=array(
    'Game'=>
    array(
        'joins'=>array(
            array('table'=>'competitions',
                  'alias'=>'Competition2',
                  'type'=>'left',
                  'conditions'=>array('Game.competition_id=Competition2.competition_id')
                  ),
            array('table'=>'teams',
                  'alias'=>'Team2',
                  'type'=>'left',
                  'conditions'=>array('Competition2.team_id=Team2.team_id')
                  ),
            ),
        'order'=>array('game_date'=>'asc'),
        'contains'=>array('Competition2'=>array('Team2'))
                    ));
function index() {
    $datum = date('Y-m-d H:m');
    $this->Game->recursive = 0;
    $scope=array('OR' => array(array('Team2.sport_id' => 2), array('Team2.sport_id' =>3)), 'Game.game_date >' => $datum);
//       Configure::write('debug',2);
    $this->set('games', $this->paginate(null,$scope));
}

感谢TehThreag帮助我

Thanks to TehThreag for helping me

这篇关于CakePHP在派生字段中分页条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆