如果我正确地阅读你的情况,听起来你可以通过避免对Thing的继承而更好地服务,而是将类别特定属性作为事物和类别之间关系的属性 .
这样的架构怎么样:
class Category {
protected $id;
protected $title;
protected $things; //@ManyToOne(targetEntity="ThingCategory")
}
class Thing {
protected $id;
protected $title;
protected $description;
protected $category; //@ManyToOne(targetEntity="ThingCategory")
}
/**
* Use [Single|Class]-Table Inheritence to model subject-category attributes.
*
* ThingCategory is just a base class. Modules provide concrete subclasses
* that encapsulate category-specific attributes.
*/
class ThingCategory {
protected $id; //surrogate key, not strictly necessary
protected $thing; //@ManyToOne(targetEntity="Thing")
protected $category //@ManyToOne(targetEntity="Category")
}
class ThingMovieCategory extends ThingCategory{
protected $airingStartDate;
protected $airingEndDate;
}
class ThingCarCategory extends ThingCategory {
protected $horespower;
protected $numberOfDoors;
protected $color;
}
所以,现在事物可以通过替换与之关联的ThingCategory实体在类别之间移动 . 事物的身份永远不会改变,只是它与类别的关系 . 包含在该类别中所需的属性是ThingCategory关系实体的属性,而不是Thing本身的属性 .
编辑:您可能遇到的问题是,在子类化实体时没有记录的修改鉴别器映射的方法 . 不幸的副作用是你的基础模块必须知道每个可能的模块 . 但这可能不是一个大问题 . 如果是,我相信可以通过让每个模块操纵基本实体的ClassMetaData来避免这种情况,但我从来没有打扰过实际的工作 .