php – 映射彼此不一致
发布时间:2020-05-25 09:14:18 所属栏目:PHP 来源:互联网
导读:我有不一致的映射问题.我在我的应用程序中有两个实体 – 联系人(具有联系人的实体…)和信息,具有该联系人信息的实体(电话,电子邮件,传真,网站等). 在我的Contact实体中,我为每种类型创建了变量,我在我的应用程序中需要它,因为这种方式更容易: /** * @ORMOneT
我有不一致的映射问题.我在我的应用程序中有两个实体 – 联系人(具有联系人的实体…)和信息,具有该联系人信息的实体(电话,电子邮件,传真,网站等). 在我的Contact实体中,我为每种类型创建了变量,我在我的应用程序中需要它,因为这种方式更容易: /** * @ORMOneToMany( targetEntity = "RelationInformations",mappedBy = "objectID",cascade={"persist"} ) */ protected $contactInformations; /** * @ORMOneToMany( targetEntity = "RelationInformations",cascade={"persist"} ) */ protected $contactPhone; /** * @ORMOneToMany( targetEntity = "RelationInformations",cascade={"persist"} ) */ protected $contactFax; /** * @ORMOneToMany( targetEntity = "RelationInformations",cascade={"persist"} ) */ protected $contactWebsite; /** * @ORMOneToMany( targetEntity = "RelationInformations",cascade={"persist"} ) */ protected $contactEmail; /** * @ORMOneToMany( targetEntity = "RelationInformations",cascade={"persist"} ) */ protected $contactCommunicator; 例如,手机的吸气器看起来像: /** * Get contactPhone * * @return DoctrineCommonCollectionsCollection */ 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; } 这样我只能通过使用此函数从我的信息中获得手机,因此在应用程序的其他位置更容易获得我想要的内容. 关系信息实体: /** * @var integer * @ORMColumn( name = "rnis_id",type = "integer",nullable = false ); * @ORMId * @ORMGeneratedValue( strategy = "AUTO") */ private $id; /** * @var integer * @ORMManyToOne( targetEntity = "RelationContact",inversedBy = "contactInformations" ) * @ORMJoinColumn( name = "rnis_object_id",referencedColumnName="rnct_id",nullable = false ); */ private $objectID; /** * @var string * @ORMColumn( name = "rnis_value",type = "string",nullable = false ) */ private $value; /** * @var string * @ORMColumn( name = "rnis_type",nullable = false,length = 1 ) */ private $type; /** * @var boolean * @ORMColumn( name = "rnis_active",type = "boolean",nullable = false ) */ private $active; /** * @var boolean * @ORMColumn( name = "rnis_default",nullable = false ) */ private $default; /** * @var string * @ORMColumn( name = "rnis_txt",nullable = true ) */ private $txt; /** * @var integer * @ORMColumn( name = "rnis_type_private_business",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.您不能在相同的mappedby键上映射相同的OneToMany关系,因此,学说映射验证的beahviour是正确传递第一个contactInformations引用而在另一个上失败. 尝试将实体映射为一对多,单向连接表,如Doctrine2 doc reference中所述 希望这有帮助 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |