Cakephp 结社困难
我现在有一些型号。这些协会如下:Cakephp 结社困难,cakephp,associations,models,Cakephp,Associations,Models,我现在有一些型号。这些协会如下: 赛程有很多比赛 活动有很多日程安排 事件有许多分歧 TeamEvent有多场比赛(两场,客场和主场) 团队有许多TeamEvent(将实际团队链接到部门) 部门有许多团队活动 我正在尝试查找每个TeamEvent的所有比赛 $this->TeamEvent->find('all', array('conditions' => array('TeamEvent.team_id' => $this->Team->id)));
- 赛程有很多比赛
- 活动有很多日程安排
- 事件有许多分歧
- TeamEvent有多场比赛(两场,客场和主场)
- 团队有许多TeamEvent(将实际团队链接到部门)
- 部门有许多团队活动
$this->TeamEvent->find('all', array('conditions' => array('TeamEvent.team_id' => $this->Team->id)));
问题是,所有匹配都被放入id为1的TeamEvent中
这是相关的SQL:
SELECT `Match`.`id`, `Match`.`schedule_id`, `Match`.`event_id`, `Match`.`home_team_id`, `Match`.`away_team_id`, `Match`.`home_result`, `Match`.`away_result`, `Match`.`matchtime`, `Schedule`.`id`, `Schedule`.`week`, `Schedule`.`map_name`, `Schedule`.`start_date`, `Schedule`.`end_date`, `Schedule`.`event_id`, `HomeTeam`.`id`, `HomeTeam`.`division_id`, `HomeTeam`.`team_id`, `HomeTeam`.`active`, `HomeTeam`.`win`, `HomeTeam`.`loss`, `AwayTeam`.`id`, `AwayTeam`.`division_id`, `AwayTeam`.`team_id`, `AwayTeam`.`active`, `AwayTeam`.`win`, `AwayTeam`.`loss` FROM `openplay`.`matches` AS `Match` LEFT JOIN `openplay`.`schedules` AS `Schedule` ON (`Match`.`schedule_id` = `Schedule`.`id`) LEFT JOIN `openplay`.`team_events` AS `HomeTeam` ON (`Match`.`home_team_id` = `HomeTeam`.`id`) LEFT JOIN `openplay`.`team_events` AS `AwayTeam` ON (`Match`.`away_team_id` = `AwayTeam`.`id`) WHERE ((`HomeTeam`.`team_id` = 1) OR (`AwayTeam`.`team_id` = 1)) ORDER BY `Match`.`matchtime` desc LIMIT 1
正如你所见,唯一的条件是客场和主场比赛。我如何使它也能执行计划检查
$this->Team->id
这将保存指向团队模型的当前指针-我不建议使用它,除非您知道自己在做什么,我建议在函数调用中使用一个参数:
public function something($team_id) {
$matches = $this->TeamEvent->find('all', array('conditions' => array('TeamEvent.team_id' => $team_id)));
//etc
}
感谢您的帮助,但即使在使用该参数时也不起作用。如果您使用控制器代码更新原始问题,可能会有所帮助