I'm trying to create a bundle where all entities can be replaceable/extendable and came across these two pages:

Now I'm trying to put it into practice for the first time, and created this simple test:

In the bundle, I created an interface for the Country entity

namespace My\Custom\Bundle\Entity;

interface CountryInterface
{
    /**
     * @return string|null
     */
    public function getIsoCode(): ?string;
}

Then, I created the entity itself

namespace My\Custom\Bundle\Entity;

/**
 * @ORM\Entity()
 */
class Country implements CountryInterface
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string|null
     * @ORM\Column(type="string", nullable=true)
     */
    private $isoCode;

    // getters/setters
}

And in my application I tried this to extend the entity:

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use My\Custom\Bundle\Entity\Country as BaseCountry;

/**
 * @ORM\Entity()
 */
class Country extends BaseCountry
{
    /**
     * @var string
     * @ORM\Column(type="string", nullable=true)
     */
    protected $name;
}

Then I added this in my doctrine configuration:

doctrine:
    orm:
        resolve_target_entities:
            My\Custom\Bundle\CountryInterface: App\Entity\Country

But when doing doctrine:migrations:diff I always get an error saying The table with name 'my_custom_bundle.country' already exists.

What am I doing wrong?

0 Answers