0
votes

I am getting two warnings about misconfigured entities in my Symfony 2 project. It runs fine in the development environment, but the production environment will not start and I suspect these misconfigured entities might be the reason.

It is the same error on both entities so I am only including one of them as an example.


BizTV\MediaManagementBundle\Entity\QrImage:

The field BizTV\MediaManagementBundle\Entity\QrImage#visits is on the inverse side of a bi-directional relationship, but the specified mappedBy association on the target-entity BizTV\MediaManagementBundle\Entity\QrVisit#QrImage does not contain the required 'inversedBy="visits"' attribute.

QrVisit entity:

class QrVisit 
{

...

/**
* @var object BizTV\MediaManagementBundle\Entity\QrImage
*  
* @ORM\ManyToOne(targetEntity="BizTV\MediaManagementBundle\Entity\QrImage")
* @ORM\JoinColumn(name="QrImage", referencedColumnName="id")
*/
protected $QrImage;

QrImage entity:

class QrImage
{

...

/**
 * @ORM\OneToMany(targetEntity="BizTV\MediaManagementBundle\Entity\QrVisit", mappedBy="QrImage")
 */
private $visits;

I changed QrImage to include the inversedBy as below, but I probably did it wrong because I still get an error message, although a new one.

/**
 * @ORM\OneToMany(targetEntity="BizTV\MediaManagementBundle\Entity\QrVisit", mappedBy="QrImage", inversedBy="visits")
 */
private $visits;

But this generates the error:

[Creation Error] The annotation @ORM\JoinColumn declared on property BizTV\UserBundle\Entity\UserGroup::$company does not have a property named "inversedBy". Available properties: name, referencedColumnName, unique, nullable, onDelete, columnDefinition, fieldName

1
What do you need? Unidirectional or bi-directional relationship?DonCallisto
QrImage can have many QrVisits, but each QrVisit only has one QrImage.Matt Welander

1 Answers

0
votes

If you want to establish a bi-directional ManyToOne / OneToMany relationship you'll have to put the mappedBy attribute on the OneToMany side like:

@ORM\OneToMany(targetEntity="BizTV\MediaManagementBundle\Entity\QrVisit", mappedBy="QrImage")

and the inversedBy on the ManyToOne side like:

@ORM\ManyToOne(targetEntity="BizTV\MediaManagementBundle\Entity\QrImage", inversedBy="visits")

that's all you need here. For your reference please check Doctrine doc

The error that you're getting refers to a different entity (UserGroup) but you can check them in the same fashion.