In my CakePHP application, I have models for matches and teams. Each match has home_team_id and away_team_id, both of which refer to another team.
In my team.php file, I can create relationships for team home matches:
var $hasMany = array( 'HomeMatch' => array('className' => 'Match', 'foreignKey' => 'home_team_id'), 'AwayMatch' => array('className' => 'Match', 'foreignKey' => 'away_team_id') );
My problem is that I cannot automatically receive commands home and in a match in one array. That is, the matches found are returned to separate arrays HomeMatch and AwayMatch, which causes difficulties in sorting.
I tried the following:
var $hasMany = array( 'Match' => array('foreignKey' => array('home_team_id', 'away_team_id')) );
... no luck.
Any ideas on how to combine these two foreign keys into one relationship?
Thanks Ben
cakephp foreign-keys relationship has-many
Ben
source share