主义2指数继承

Har*_*rry 5 php indexing inheritance doctrine-orm

我是Doctrine 2的新手,我试图找出如何使用它进行索引继承.

我想要实现的是拥有一个基类,它定义了一些默认列以及应用程序中所有实体的必要索引.

示例:我的应用程序中的所有表都将具有created_onmodified_on,因此我准备了一个@MappedSuperclass包含其中2列的基础.

这是我的代码:

<?php

/**
 * @MappedSuperclass
 */
abstract class EntityAbstract
{
    /**
     * @Column(type="datetime", name="created_on", nullable=false)
     */
    protected $createdOn;

    /**
     * @Column(type="datetime", name="modified_on", nullable=true)
     */
    protected $modifiedOn;

}

/**
 * @Entity
 * @Table(name="member", indexes={@Index(name="credential", columns={"email_address", "password"})})
 */
class Member extends EntityAbstract
{
    /**
     * @Column(type="string", name="full_name", length=50)
     */
    protected $fullName;

    /**
     * @Column(type="string", name="email_address", length=50, unique=true, nullable=false)
     */
    protected $emailAddress;

    /**
     * @Column(type="string", name="password", length=40, nullable=false)
     */
    protected $password;       

}
?>
Run Code Online (Sandbox Code Playgroud)

我想强制created_on成为一个索引,所以我把@Index注释放在这个特定列的基类中.希望这将导致2个索引Member,其是created_onemail_address+ password的组合.但是,这会导致子类的索引被子类覆盖,因此created_on不是索引.

/**
 * @MappedSuperclass
 * @Table(indexes={@Index(name="timestampcreated", columns={"created_on"})})
 */
abstract class EntityAbstract
Run Code Online (Sandbox Code Playgroud)

我如何在Doctrine 2中实现这一目标?看过单表继承,但我的理解是它意味着不同的目的.

nac*_*bre 1

我想做同样的事情,但课堂@Table上不允许@mappedSuperclass。我已经在doctrine2 github页面上发布了问题https://github.com/doctrine/doctrine2/issues/5928,答案是:

@Table 在映射的超类上无效。

当你想到它时,这听起来很合乎逻辑,但如果有这样的功能,继承索引和其他声明,那就太好了。