我有不一致的映射问题。我的应用程序中有两个实体-联系人(具有联系人实体...)和信息,具有与此联系人的信息(电话,电子邮件,传真,网站等)的实体。
在我的Contact实体中,我为每种类型都创建了变量,我在应用程序中需要它,因为这种方式更容易:
/**
* @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.
您不能OneToMany
在相同的mappedby
键上映射相同的关系,因此,原理映射验证的行为是正确地传递第一个contactInformations
引用,而在另一个引用上失败。
尝试One-To-Many, Unidirectional with Join Table
按照Doctrine2文档参考中的描述映射实体
希望有帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句