简体   繁体   English

Doctrine & Symfony3 OneToOne 关系,反面不存在

[英]Doctrine & Symfony3 OneToOne relations, inverse side does not exist

I am looking for a clear explanation of how the relations work in Doctrine 2. I've been trying now for days to set up a OneToOne relation in Symfony3, and have read basically every thread and all the documentation, and i simply do not understand.我正在寻找有关 Doctrine 2 中关系如何工作的明确解释。我已经尝试了几天在 Symfony3 中建立 OneToOne 关系,并且基本上阅读了每个线程和所有文档,但我根本不明白. The last few hours i've been bruteforcing my way into a OneToOne relation, with no luck.在过去的几个小时里,我一直在强行进入一对一关系,但没有运气。 Here's the problem i'm dealing with:这是我正在处理的问题:

My user entity has a Team (which is itself an Entity)我的用户实体有一个团队(它本身就是一个实体)

/**
* @ORM\OneToOne(targetEntity="Gluckez\bballBundle\Entity\Team", 
mappedBy="Owner")
* @ORM\Column(name="team_id")
*/
private $team;

And My Team has an Owner, which refers to the User:我的团队有一个所有者,指的是用户:

/**
 * @var User $Owner  
 * @ORM\OneToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", 
inversedBy="team_id")
 * @ORM\JoinColumn(name="Owner_id", referencedColumnName="id")
 */
protected $Owner;

Now in my User table, i can see the relations, which do point to the right team.现在在我的用户表中,我可以看到指向正确团队的关系。 but doctrine complains about the inverse side User#team, that does not exist (even though i'm pretty sure i've defined it?) I've tried countless times to change the inversedby, mappedby, name, referencedcolumnName, as well as dropping and recreating the database and tables.但是学说抱怨反面 User#team,它不存在(即使我很确定我已经定义了它?)我已经无数次尝试更改 inversedby、mappedby、name、referencedcolumnName 以及删除并重新创建数据库和表。 updating the doctrine schema's.更新教义模式。 i'm out of idea's.我没主意了。 Not a single answer out there, nor the documentation of doctrine points me in the right direction.那里没有一个答案,也没有教义文件指出我正确的方向。 I realize that there's a lot of threads out there on this, but none of them are clear, or even answered.我意识到在这方面有很多线索,但没有一个是清楚的,甚至没有答案。

Try it like this:像这样尝试:

Owner entity所有者实体

/**
* @ORM\OneToOne(targetEntity="Gluckez\bballBundle\Entity\Team", mappedBy="owner")
*/
private $team;

Team entity团队实体

/**
 * @ORM\OneToOne(targetEntity="Application\Sonata\UserBundle\Entity\User", inversedBy="team")
 */
protected $owner;

As reference: Association Mapping作为参考: 关联映射

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM