2014-10-08 19 views
6

Mam problem z niespójnymi odwzorowaniami. Mam w mojej aplikacji dwie jednostki - Kontakt (podmiot z kontaktami ...) oraz Informacje, podmioty z informacjami do tego kontaktu (telefony, e-maile, faksy, strony internetowe itp.).Mapowania są niezgodne ze sobą

i moim podmiot kontaktowy zrobiłem zmiennych dla każdego typu, muszę go w mojej aplikacji, ponieważ w ten sposób jest dużo łatwiejsze:

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

i przykładowo getter dla telefonów wygląda następująco:

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

W ten sposób mam tylko telefony z moich informacji tylko za pomocą tej funkcji, więc jest to znacznie łatwiejsze w innych miejscach w aplikacji, aby uzyskać to, co chcę.

RelationInformation Podmiot:

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

Problemem jest to, że w moim profiler widzę błędy jak mieszka. Aplikacja działa poprawnie, ale chcę rozwiązać ten 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. 
+0

proszę pisać kod podmiotu 'RelationInformations' – Matteo

+0

Ok, muszę dodać go;) –

Odpowiedz

8

Nie można odwzorować te same OneToMany stosunki na tej samej mappedby klucza, więc beahviour walidacji mapowania doktryna jest prawidłowo przechodzić pierwszy contactInformations odniesienia a nie na innych.

Spróbuj mapować podmioty jak One-To-Many, Unidirectional with Join Table jak opisano w Doctrine2 doc reference

Nadziei to pomóc

+1

Dałeś mi Pomysł rozwiązania tego problemu, wypróbuję go już teraz i napiszę, gdy będę wiedział coś więcej ;-) –

+0

Wszystko wygląda dobrze, ale ... Kiedy mam w mojej formie kolekcję odwzorowaną na przykład na "contactPhone". Telefony wyglądają poprawnie, ale kiedy chcę dodać telefon, mam błąd, że w "ClassMetadata" nie ma takiego klawisza jak contactPhone (ponieważ nie ma teraz powiązania, więc ta kolekcja nie jest "naturalna"). Wszelkie pomysły Matteo? :-) –

+1

Spójrz na relacje doctrine2 o nazwie "Jeden do wielu, Jednokierunkowy z dołączoną tabelą" i sprawdź, czy spełniasz wymagania. – Matteo

Powiązane problemy