映射彼此不一致 [英] The mappings are inconsistent with each other

查看:155
本文介绍了映射彼此不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

希望有帮助

这篇关于映射彼此不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆