扩展SINGLE_TABLE继承

时间:2013-12-28 14:52:39

标签: inheritance doctrine-orm

我有一个使用单表继承的现有应用程序:

/**
 * @Entity
 * @Table(name="entities")
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="class", type="string")
 * @DiscriminatorMap({
 *      "channel" = "Channel",
 *      "aggregator" = "Aggregator"
 * })
 * @HasLifecycleCallbacks
 */

通过DQL搜索实体:

$dql = 'SELECT a FROM Volkszaehler\Model\Entity a

获取类型为channelaggregator的所有实体,这就是生成的SQL:

SELECT e0_.id AS id0, e0_.uuid AS uuid1, e0_.type AS type2, e0_.class AS class6, 
FROM entities e0_ 
WHERE e0_.class IN ('channel', 'aggregator')

当我试图通过扩展DiscriminatorMap来扩展继承时

 * @DiscriminatorMap({
 *      "channel" = "Channel",
 *      "aggregator" = "Aggregator",
 *      "generic" = "GenericEntity"
 * })

找不到新的generic类型,因为SQL保持不变 - 将查询限制为channelaggregator

我会感谢任何提示在SINGLE_TABLE继承上控制SQl生成的任何提示。

1 个答案:

答案 0 :(得分:0)

事实证明问题在于缓存。上面给出的实现是正确的,但元数据没有刷新(这是令人困惑的,因为我可以创建新的实体类型,但找不到它):

$config->setMetadataCacheImpl($cache);
// rebuild cache!
$cache->deleteAll();