我认为您应该为 map_numbers 表创建一个模型,并使该模型与活动相关,并且活动不应与 track_numbers 或 target_numbers 直接相关。像这样的东西:
Class Campaign extends DataMapper {
public $has_many = array('map_numbers' => array('class' => 'Map_Number'));
}
Class Map_Number extends DataMapper {
public $has_one = array(
'campaign' => array('other_field' => 'map_numbers'),
'target_number' => array('other_field' => 'map_numbers'),
'track_number' => array('other_field' => 'map_numbers'),
);
}
class Target_Number extends DataMapper {
public $has_many = array('map_numbers' => array('class' => 'Map_Number'));
}
class Track_Number extends DataMapper {
public $has_many = array('map_numbers' => array('class' => 'Map_Number'));
}
所以你的结构看起来像这样(在光荣的 ascii 艺术中):
+------------------+
+----------+ | 地图编号 |
| 活动 | +-----------------+ +----------------+
+----------+ | 编号 | | 目标号码 |
| 编号 |<--| 活动 ID | +----------------+
+----------+ | target_number_id |---->| 编号 |
| track_number_id |-+ +----------------+
+------------------+ |
| +----------------+
| | 轨道号码 |
| +----------------+
+-->| 编号 |
+----------------+
other_field
和参数仅在class
您想使用复数形式进行$has_many
关联时才需要。