2014-10-08 8 views
6

Ho un problema con i mapping incoerenti. Nella mia applicazione ho due entità: contatto (entità con contatti ...) e informazioni, entità con informazioni su questo contatto (telefoni, e-mail, fax, siti Web, ecc.).I mapping sono incoerenti tra loro

e nella mia entità di contatto che ho fatto le variabili per ogni tipo, ne ho bisogno nella mia domanda perché in questo modo è molto più facile:

/** 
* @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; 

E per esempio getter per i telefoni assomiglia:

/** 
* 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; 
} 

In questo modo ho ottenuto solo i telefoni dalle mie informazioni solo utilizzando questa funzione, quindi è molto più semplice in altri posti dell'applicazione ottenere ciò che voglio.

RelationInformation Entity:

/** 
    * @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; 

Il problema è che nel mio profiler posso vedere errori come muggito. L'applicazione funziona correttamente ma voglio risolvere questo problema.

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

si prega di inviare il codice dell'Ente 'RelationInformations' – Matteo

+0

Ok, ho aggiungerlo;) –

risposta

8

Non è possibile mappare gli stessi OneToMany rapporti sullo stesso tasto mappedby, in modo che il beahviour della convalida mappatura dottrina è quello di passare correttamente il primo riferimento contactInformations e non riescono sull'altro.

tenta di connettere le vostre entità One-To-Many, Unidirectional with Join Table come descritto nella Doctrine2 doc reference

Spero che questo aiuto

+1

Mi ha dato un idea come risolverlo, lo proverò proprio adesso e scriverò quando saprò qualcosa di più ;-) –

+0

Tutto sembra okey ma ... Quando ho nella mia raccolta moduli mappata su 'contactPhone' per esempio. I telefoni vengono visualizzati correttamente, ma quando voglio aggiungere un telefono ho un errore che in "ClassMetadata" non esiste una chiave come contactPhone (perché non esiste alcuna relazione ora, quindi questa raccolta non è "naturale"). Qualche idea, Matteo? :-) –

+1

Osserva le relazioni doctrine2 denominate "One-To-Many, Unidirectional with Join Table" e verifica se soddisfano le tue esigenze. – Matteo

Problemi correlati