简体   繁体   中英

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. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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