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