【发布时间】:2014-07-08 04:26:37
【问题描述】:
我目前有几个模型。关联如下:
- 安排 hasMany Match
- 事件有很多时间表
- 事件有很多部门
- TeamEvent hasMany Match(两场,客场和主场)
- Team hasMany TeamEvent(将实际团队链接到部门)
- Division hasMany 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
如您所见,唯一的条件是 Away and Home TeamEvent。我怎样才能让它也检查时间表?
【问题讨论】:
标签: cakephp associations models