我真的在为 cakephp 中的表关联而苦苦挣扎,我想做的就是将两个表关联在一起,但是一个表有两个外键到另一个表。
出于某种原因,我无法在 home_id ... 的字段选择表单中显示任何信息。
请参阅下面的数据库图片和相关代码。
我对 cakephp 真的很陌生,但觉得如果我能做到这一点,这将非常有用 - 非常感谢任何帮助。
class SafcTeam extends AppModel {
var $name = 'SafcTeam';
var $displayField = 'name';
var $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'badge' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
);
var $hasMany = array(
'SafcTeam' => array(
'className' => 'SafcEvent',
'foreignKey' => 'home_id',
)
);
}
class SafcEvent extends AppModel {
var $name = 'SafcEvent';
var $displayField = 'id';
var $validate = array(
'safc_matchtype_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'safc_league_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'home_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'away_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'streamer_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'safc_channel_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'comments' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'safc_profile_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'safc_source_id' => array(
'numeric' => array(
'rule' => array('numeric'),
),
),
'event_info_url' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
);
var $belongsTo = array(
'SafcMatchtype' => array(
'className' => 'SafcMatchtype',
'foreignKey' => 'safc_matchtype_id'
),
'SafcLeague' => array(
'className' => 'SafcLeague',
'foreignKey' => 'safc_league_id'
),
'SafcChannel' => array(
'className' => 'SafcChannel',
'foreignKey' => 'safc_channel_id'
),
'SafcProfile' => array(
'className' => 'SafcProfile',
'foreignKey' => 'safc_profile_id'
),
'SafcSource' => array(
'className' => 'SafcSource',
'foreignKey' => 'safc_source_id'
),
'SafcTeam' => array(
'className' => 'SafcTeam',
'foreignKey' => 'home_id'
)
);
}