【发布时间】:2013-12-13 02:12:22
【问题描述】:
我是 Doctrine 2 的新手,我想弄清楚如何使用它进行索引继承。
我想要实现的是有一个基类,它定义了一些默认列以及应用程序中所有实体的必要索引。
示例:我的应用程序中的所有表都有created_on 和modified_on,所以我准备了一个基础@MappedSuperclass,其中包含这两列。
这是我的代码:
<?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;
}
?>
我想强制 created_on 成为索引,所以我将 @Index 注释放在这个特定列的基类中。希望这将为Member 产生两个索引,即created_on 和email_address+password 组合。然而,这会导致基类的索引被子类覆盖,因此created_on 不是索引。
/**
* @MappedSuperclass
* @Table(indexes={@Index(name="timestampcreated", columns={"created_on"})})
*/
abstract class EntityAbstract
我如何在 Doctrine 2 中实现这一点?看过单表继承,但我的理解是它有不同的目的。
【问题讨论】:
标签: php inheritance doctrine-orm indexing