流向双向一对一关系

编程入门 行业动态 更新时间:2024-10-24 22:31:03
本文介绍了流向双向一对一关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在流量中是否有一对一关系,而不必设置属性两次?

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.

更多推荐

流向双向一对一关系

本文发布于:2023-11-16 11:51:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1604030.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:流向   双向   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!