加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Doctrine 2:有没有办法使用yaml或xml从特征继承映射?

发布时间:2020-12-13 17:56:27 所属栏目:PHP教程 来源:网络整理
导读:我找到了 following example in the doctrine documentation,他们已经添加了映射到特征: /** * Trait class */trait ExampleTrait{ /** @Id @Column(type="string") */ private $id; /** * @Column(name="trait_foo",type="integer",length=100,nullable=tr
我找到了 following example in the doctrine documentation,他们已经添加了映射到特征:
/**
 * Trait class
 */
trait ExampleTrait
{
    /** @Id @Column(type="string") */
    private $id;

    /**
     * @Column(name="trait_foo",type="integer",length=100,nullable=true,unique=true)
     */
    protected $foo;

    /**
     * @OneToOne(targetEntity="Bar",cascade={"persist","merge"})
     * @JoinColumn(name="example_trait_bar_id",referencedColumnName="id")
     */
    protected $bar;
}

我试图映射一个特征,而不必复制继承它的类中的映射.我没有诚实地尝试过这个,因为我当前的项目使用yaml进行映射,但看起来普通的php类在使用特性时也会继承映射.

有没有办法继承这个特征的映射而不使用关联,而是使用yaml或xml?我尝试将特性设置为mapped superclass,但它没有用,但我基本上都在寻找相同类型的想法.

谢谢.

使用YAML声明mappedSupperClass:
NamespaceForYourMappingClass:
    type: mappedSuperclass
    fields:
        id:
            id:
                type: integer
                generator:
                    strategy: AUTO

        ... other fields and relations

用XML声明它:

<?xml version="1.0" encoding="UTF-8"?>
<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
                  http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <mapped-superclass name="NamespaceForYourMappingClass">

        <field name="foo" column="foo" type="string" length="255" />

        <field name="bar" column="bar" type="string" length="255" unique="true" />

        ... other fields

    </mapped-superclass>

</doctrine-mapping>

如果您运行app / console doctrine:generate:entities,您将能够在其他实体中使用mappedSuperClass作为优势.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读