我正在尝试从我的模型中找到设计实体之间关系的最佳方法。我会尽力解释清楚。
想象一下以下 Doctrine2 实体:
class ImageHistory
{
/**
* @var Image
*/
protected $current;
/**
* @var \Doctrine\Common\Collections\Collection
*/
protected $old;
}
class Dog
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
class Cat
{
protected $name;
/**
* @var ImageHistory
*/
protected $imageHistory;
}
我想建立两个一对多的双向学说关系,Cat并且Dog是关系的拥有方。Cat和类都有Dog这个实体配置:
manyToOne:
imageHistory:
targetEntity: ImageHistory
joinColumn:
name: image_history_id
referencedColumnName: id
如何表示 te 关系的另一方?
oneToMany:
owner:
targetEntity: <What can I write here?>
mappedBy: imageHistory
我想象一个解决方案,其中Cat继承Dog一个Animal实体类,因此我可以将 ManyToOne 关系移动到Animal类中并Animal作为 OneToMany 关系的 targetEntity。但是,如果我有一个新SoundHistory实体和 : Cat,Dog并且新的Car和Boat类必须与它有关系,问题就会再次出现。
A 不能只添加SoundHistory作为Animal类的 oneToMany 关系,因为Car并且Boat不会从它继承。所以我仍然无法在实体中填充targetEntity我的 OneToMany 关系。ImageHistory
在这种情况下设计实体模型的最佳方法是什么?