[eluser]thevenin[/eluser]
Hi.
In php-activerecord it is easy to create association with foreign table when we're using standard field names ("
user_id", "
post_id", etc.) and there is only one FK associated with one foreign table:
user_id ->
users table,
post_id ->
posts table, etc.
In my database I would like to retrieve teams' names for each match (table:
matches).
Every match record has 2 foreign keys:
Code:
home_team_id // referring to "teams.name"
Code:
away_team_id // referring to "teams.name"
I know how to create query in plain SQL but I would like to use php-activerecord.
Do you have any idea how to create delegates/associations to retrieve teams' names in
$match object?
"teams" table:
Code:
CREATE TABLE `teams` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(32) NOT NULL,
`short_name` varchar(16) DEFAULT NULL,
`code` varchar(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
"matches" table:
Code:
CREATE TABLE `matches` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`home_team_id` int(11) unsigned NOT NULL,
`away_team_id` int(11) unsigned NOT NULL,
`home_goals` enum('0','1','2','3','4','5','6','7','8','9','10') NOT NULL DEFAULT '0',
`away_goals` enum('0','1','2','3','4','5','6','7','8','9','10') NOT NULL DEFAULT '0',
`starting_at` datetime NOT NULL,
`status` enum('not_started','afoot','finished') NOT NULL DEFAULT 'not_started',
`stage` enum('group_a','group_b','group_c','group_d','quarter_final','semi_final','final') NOT NULL,
PRIMARY KEY (`id`),
KEY `home_team` (`home_team_id`),
KEY `away_team` (`away_team_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;