代码之家  ›  专栏  ›  技术社区  ›  Mike Doe Backs

映射原则的一对一关系作为XML中的主键

  •  0
  • Mike Doe Backs  · 技术社区  · 6 年前

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

    如何将此映射保存为XML?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Mike Doe Backs    6 年前

    知道了:

    <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" 因此,教义不再抱怨拥有 user 已经有财产了。