ReynierPM
ReynierPM

Reputation: 18660

Understanding how owning side in a bidirectional relationship works

I'm validating a project schema using php app/console doctrine:schema:validate task (codes aren't mine I'm just trying to get this works fine). One of the common messages I can see is this one:

  • The field Mapyet\AfiliadoBundle\Entity\Widget#negocio is on the owning side of a bi-directional relationship, but the specified mappedBy association on the target-entity Mapyet\AfiliadoBundle\Entity\Negocio# does not contain the required 'inversedBy' attribute.

This is how $negocio is defined at Widget.php entity:

/**
 * @ORM\ManyToOne(targetEntity="Negocio", mappedBy="widget")
 */
private $negocio;

This is how $widget is defined at Negocio.php entity:

/**
 * @ORM\OneToMany(targetEntity="Widget", inversedBy="negocio")
 */
private $widget;

What is wrong in that definition?

Upvotes: 2

Views: 5703

Answers (1)

zizoujab
zizoujab

Reputation: 7800

Inverse them :

Widget.php

/**
 * @ORM\ManyToOne(targetEntity="Negocio", inversedBy="widget")
 */
private $negocio;

Negocio.php

/**
 * @ORM\OneToMany(targetEntity="Widget", mappedBy="negocio")
 */
private $widget;

http://docs.doctrine-project.org/en/2.0.x/reference/association-mapping.html#one-to-many-bidirectional

Upvotes: 5

Related Questions