在流量中是否有一对一关系,而不必设置属性两次?
Is it possible to have One-To-One Relationships in Flow without having to set the attributes twice?
我有两张以一对一关系连接的表格,但只有其中一个表格应包含此关系的额外列。
I have two tables that are connected in a One-To-One Relationship, but only one of them should contain an extra column for this Relation.
明确的原则支持这种行为: doctrine-orm.readthedocs/en/latest/reference/association-mapping.html#one-to-one-bidirectional
Doctrine clearly supports this behavior: doctrine-orm.readthedocs/en/latest/reference/association-mapping.html#one-to-one-bidirectional
应该带有一个componenttape列的类:
The class that should come with a componenttape column:
/** * @Flow\Entity */ class Component{ /** * @var \Some\Package\Domain\Model\Component\Tape * @ORM\OneToOne(cascade={"all"}, inversedBy="component") */ protected $componentTape; … }应该只能找到连接的类没有额外的列:
The class that should just be able to find the connection without an extra column:
/** * @Flow\Entity */ class Tape{ /** * @var \ Some\Package\Domain\Model\Component * @ORM\OneToOne(mappedBy="componentTape") */ protected $component; }一个学说更新将为这两个模型创建额外的列。
A doctrine update will create extra columns for both models.
这是我现在的工作环境如下所示:
This is what my workarround at the moment looks like:
class Component{ .. /** * @param \Some\Package\Domain\Model\Component\Tape $componentTape * @return void */ public function setComponentTape($componentTape) { $this->componentTape = $componentTape; $this->componentTape->setComponent($this); }推荐答案
解决方法无论如何也是必要的在请求期间始终保持关系正确。 但是第二个DB列不应该是必需的。你检查了教义是否真的填补了?也许/可能只是创建的迁移是错误的,磁带中的组件列可以省略。
The workaround will be necessary anyway to keep the relation correct at all times during a request. But the second DB column shouldn't be necessary. Did you check if doctrine actually fills it? Maybe/Probably just the created migration is wrong and the component column in Tape can be omitted.
更多推荐
流向双向一对一关系
发布评论