jankstudio / catalyst-discriminator-map-bundle

Catalyst Doctrine Discriminator Map Bundle

dev-master 2016-12-15 21:17 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:44:18 UTC


README

Symfony 扩展包,允许在包配置文件中指定 Doctrine 判别器映射,而不是在父实体下。

此扩展包消除了父实体对子实体的依赖。

配置

最低要求是在包的 Resources/config 目录下有一个 dmap.yml 文件,其中包含父实体。

示例 dmap.yml 文件

entities:
    - parent: MyBundle\Entity\Person
      children:
        - id: person
          class: MyBundle\Entity\Person
        - id: employee
          class: MyBundle\Entity\Employee

您可以在其他包中拥有具有相同父实体的其他 dmap.yml 文件,如下所示

entities:
    - parent: MyBundle\Entity\Person
      children:
        - id: customer
          class: AnotherBundle\Entity\Customer

判别器映射示例

判别器映射通常是如何完成的

实体

<?php
namespace MyProject\Entity;

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

/**
 * @Entity
 */
class Employee extends Person
{
    // ...
}

如何使用此扩展包完成

实体

<?php
namespace MyProject\Entity;

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 */
class Person
{
    // ...
}

/**
 * @Entity
 */
class Employee extends Person
{
    // ...
}

配置文件(dmap.yml)

entities:
    - parent: MyProject\Entity\Person
      children:
        - id: person
          class: MyProject\Entity\Person
        - id: employee
          class: MyProject\Entity\Employee