将教义的一对一关系映射为XML中的主键

时间:2018-11-26 12:42:12

标签: php doctrine

考虑示例实体:

class Entity
{
    /**
     * @Id
     * @OneToOne(targetEntity="AppBundle\Entity\User")
     */
    public $user;
}

如何以XML保存此映射?

1 个答案:

答案 0 :(得分:0)

知道了

<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
                   https://raw.github.com/doctrine/doctrine2/master/doctrine-mapping.xsd">
    <entity name="AppBundle\Entity\Entity">
        <id association-key="true" name="user" />
        <one-to-one field="user" target-entity="AppBundle\Entity\User" />
    </entity>
</doctrine-mapping>

关键部分是association-key="true",因此Doctrine不再抱怨已经拥有user属性。