How to make Doctrine Migrations generate appropriate SQL for inheritance tables?

I have two entities A and B, where B extends A:

/**
 * Fruit
 *
 * @ORMTable(
 *     name="fruits",
 *     indexes={}
 * )
 * @ORMEntity
 * @ORMInheritanceType("JOINED")
 * @ORMDiscriminatorColumn(name="type", type="string")
 * @ORMDiscriminatorMap({
 *     "apple" = "Apple"
 * })
 */
abstract class Fruit extends AbstractEntity
{
    /**
     * @var string
     * @ORMColumn(type="string" ...)
     */
    private $color;
}

/**
 * Apple
 *
 * @ORMTable(
 *     name="apples",
 *     indexes={}
 * )
 * @ORMEntity
 */
class Apple extends Fruit
{
    /**
     * @var string
     * @ORMColumn(type="string" ...)
     */
    private $foo;
}

When I run the migrations command (e.g. $ ./bin/console doctrine:migrations:diff) I expect it to create two tables and in apples a FOREIGN KEY on the id column, referencing the fruit.id. But this reference is missing.

How to get Doctrine Migrations to define the reference from the child_table.id to the parent_table.id? Or is it the only way to do this on oneself by editing the generated SQL manually?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *