映射彼此不一致

编程入门 行业动态 更新时间:2024-10-28 02:29:31
本文介绍了映射彼此不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有不一致的映射的问题。我在我的申请两个实体 - 联系人(实体与联系人...)和信息,实体与此联系(电话,电子邮件,传真,网站等)的信息。

I have problem with inconsistent mappings. I have in my application two entities - Contact (entity with contacts...) and Information, entities with informations to this contact (phones, emails, fax, websites etc.).

在我的Contact实体中,我为每个类型创建了变量,我需要它在我的应用程序,因为这种方式更容易:

And In my Contact entity I made variables for each type, I need it in my application because this way is much easier:

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

例如手机的getter类似:

And for example getter for phones looks like:

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

这种方式我只有从我的信息只有手机使用此功能,所以它

This way i got only phones from my informations only by using this function so it's much easier in other places in application to get what I want.

关系信息实体:

/** * @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 problem is that in my profiler i can see errors like bellow. Application works correctly but I want to solve this issue.

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.

推荐答案

c> c => 关键字,因此,doctrine映射验证的beahviour是正确地传递第一个

You can't map the same OneToMany relations on the same mappedby key, so the beahviour of the doctrine mapping validation is to correctly pass the first contactInformations reference and fail on the other.

尝试将您的实体映射为一对多,单向与按照 Doctrine2 doc reference

Try to map your entities as One-To-Many, Unidirectional with Join Table as described in the Doctrine2 doc reference

希望有帮助

更多推荐

映射彼此不一致

本文发布于:2023-11-17 06:03:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!