映射彼此不一致

时间:2021-09-07 06:47:23

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.).

我有不一致映射的问题。在我的应用程序中有两个实体——联系人(联系人……实体)和信息,与此联系人有信息的实体(电话、电子邮件、传真、网站等)。

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;

And for example getter for phones looks like:

例如,手机的getter如下:

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

通过这种方式,我只能从我的信息中获得手机,只能通过使用这个功能,所以在其他应用程序中更容易得到我想要的东西。

RelationInformation Entity:

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 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.

1 个解决方案

#1


8  

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.

不能在相同的mappedby键上映射相同的OneToMany关系,所以学说映射验证的beahviour是正确地传递第一个contactinformation引用,而在另一个上面失败。

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

试着将您的实体映射为一对多的、单向的,并按照教条2 doc引用中所述的连接表。

Hope this help

希望这有助于

#1


8  

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.

不能在相同的mappedby键上映射相同的OneToMany关系,所以学说映射验证的beahviour是正确地传递第一个contactinformation引用,而在另一个上面失败。

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

试着将您的实体映射为一对多的、单向的,并按照教条2 doc引用中所述的连接表。

Hope this help

希望这有助于