Tôi gặp sự cố với ánh xạ không phù hợp. Tôi có trong ứng dụng của tôi hai thực thể - Liên hệ (thực thể với địa chỉ liên lạc ...) và Thông tin, thực thể với thông tin liên lạc này (điện thoại, email, fax, các trang web, vv).Các ánh xạ không phù hợp với nhau
Và Trong tổ chức Liên hệ của tôi, tôi đã biến đối với từng loại, tôi cần nó trong ứng dụng của tôi, vì cách này là dễ dàng hơn nhiều:
/**
* @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;
Và ví dụ getter cho điện thoại trông giống như:
/**
* 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;
}
Bằng cách này tôi chỉ nhận được điện thoại từ thông tin của tôi chỉ bằng cách sử dụng chức năng này vì vậy nó dễ dàng hơn nhiều ở những nơi khác trong ứng dụng để có được những gì tôi muốn.
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;
Vấn đề là trong hồ sơ của tôi, tôi có thể thấy lỗi như dưới đây. Ứng dụng hoạt động chính xác nhưng tôi muốn giải quyết vấn đề này.
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.
xin vui lòng gửi mã của Entity 'RelationInformations' – Matteo
Ok, tôi có thêm nó;) –