Mappings are incompatible with each other

I have a problem with inconsistent mappings. I have two objects in my application - Contact (an entity with contacts ...) and Information, organizations with information about this contact (telephones, emails, fax, websites, etc.).

And in my Contact object, I created variables for each type, I need it in my application, because this method is much simpler:

/** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactInformations; /** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactPhone; /** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactFax; /** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactWebsite; /** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactEmail; /** * @ORM\OneToMany( targetEntity = "RelationInformations" , mappedBy = "objectID", cascade={"persist"} ) */ protected $contactCommunicator; 

And, for example, getter for phones looks like this:

 /** * Get contactPhone * * @return \Doctrine\Common\Collections\Collection */ public function getContactPhone() { if ($this->contactPhone !== null) { foreach ($this->contactPhone->toArray() as &$info) { if ($info->getType() !== RelationInformations::TYPE_TELEPHONE) { $this->contactPhone->removeElement($info); } } } return $this->contactPhone; } 

Thus, I got only phones from my information, only using this function, so that in other places of the application it is much easier to get what I want.

Value Information:

  /** * @var integer * @ORM\Column( name = "rnis_id" , type = "integer" , nullable = false ); * @ORM\Id * @ORM\GeneratedValue( strategy = "AUTO") */ private $id; /** * @var integer * @ORM\ManyToOne( targetEntity = "RelationContact" , inversedBy = "contactInformations" ) * @ORM\JoinColumn( name = "rnis_object_id" , referencedColumnName="rnct_id", nullable = false ); */ private $objectID; /** * @var string * @ORM\Column( name = "rnis_value" , type = "string" , nullable = false ) */ private $value; /** * @var string * @ORM\Column( name = "rnis_type" , type = "string" , nullable = false , length = 1 ) */ private $type; /** * @var boolean * @ORM\Column( name = "rnis_active" , type = "boolean" , nullable = false ) */ private $active; /** * @var boolean * @ORM\Column( name = "rnis_default" , type = "boolean" , nullable = false ) */ private $default; /** * @var string * @ORM\Column( name = "rnis_txt" , type = "string" , nullable = true ) */ private $txt; /** * @var integer * @ORM\Column( name = "rnis_type_private_business" , type = "integer" , nullable = true ) */ private $typePrivateBusiness; 

The problem is that in my profiler I can see errors like below. The application is working correctly, but I want to solve this problem.

 The mappings RelationContact#contactPhone and RelationInformations#objectID are inconsistent with each other. The mappings RelationContact#contactFax and RelationInformations#objectID are inconsistent with each other. The mappings RelationContact#contactWebsite and RelationInformations#objectID are inconsistent with each other. The mappings RelationContact#contactEmail and RelationInformations#objectID are inconsistent with each other. The mappings RelationContact#contactCommunicator and RelationInformations#objectID are inconsistent with each other. The mappings RelationContact#contactBrand and RelationInformations#objectID are inconsistent with each other. 
+6
source share
1 answer

You cannot match the same OneToMany relationship with the same mappedby key, so the doahtory doahviour must correctly pass the first contactInformations link and fail on the other.

Try matching your objects as One-To-Many, Unidirectional with Join Table , as described in the Doctrine2 doc link

Hope for this help

+8
source

Source: https://habr.com/ru/post/976412/


All Articles