2014-10-08 76 views
6

我遇到映射不一致的問題。我在應用程序中有兩個實體 - 聯繫人(包含聯繫人的實體...)和信息,包含此聯繫人信息的實體(電話,電子郵件,傳真,網站等)。映射彼此不一致

,在我跟實體我做變量爲每種類型的,我需要在我的應用程序,因爲這樣更容易:

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

而且例如吸氣的手機看起來像:

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

這樣我只通過使用這個函數從我的信息中獲得手機,所以在應用程序的其他地方更容易得到我想要的。

RelationInformation實體:

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

請張貼實體'RelationInformations' – Matteo 2014-10-08 10:06:03

+0

確定的代碼,我已經將其添加;) – 2014-10-08 10:09:55

回答

8

不能映射在同一mappedby鍵相同OneToMany關係,所以學說映射驗證的beahviour是正確傳遞第一contactInformations參考,並不能爲另一方。

嘗試,因爲這有助於在Doctrine2 doc reference

希望您描述實體One-To-Many, Unidirectional with Join Table地圖

+1

你給了我一個想法如何解決它,我現在會嘗試,我會寫,當我知道更多的東西;-) – 2014-10-08 10:29:14

+0

一切都看起來okey,但...當我在我的表單集合映射到'contactPhone'例如。手機顯示正確,但是當我想添加手機時,我有一個錯誤,在'ClassMetadata'中沒有接觸電話這樣的鍵(因爲現在沒有關係,所以這個集合不是'自然')。任何想法Matteo? :-) – 2014-10-08 10:39:46

+1

看看名爲'一對多,單向連接表'的doctrine2關係,看看是否滿足你的要求。 – Matteo 2014-10-08 10:49:27