I am looking for a solution to the following database inheritance problem using Doctrine 2 built into the Symfony 2 framework. This is what I want to do ...

I want to create two tables (UredniHodiny, KonzultacniHodiny) with the same interface as the abstract Hodiny class. This is how i try to do it
<?php // src/CvutPWT/ImportBundle/Entity/Hodiny.php namespace CvutPWT\ImportBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\MappedSuperclass */ abstract class Hodiny { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\ManyToOne(targetEntity="Osoba") */ protected $osoba; /** * @ORM\ManyToOne(targetEntity="Mistnost") */ protected $mistnost; /** * @ORM\Column(type="datetime") */ protected $zacatek; /** * @ORM\Column(type="datetime") */ protected $konec; } <?php // src/CvutPWT/ImportBundle/Entity/KonzultacniHodiny.php namespace CvutPWT\ImportBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="konzultacnihodiny") */ class KonzultacniHodiny extends Hodiny { } <?php // src/CvutPWT/ImportBundle/Entity/UredniHodiny.php namespace CvutPWT\ImportBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="urednihodiny") */ class UredniHodiny extends Hodiny { }
Now, when I run the php app/console doctrine:generate:entities CvutPWTImportBundle
, Symfony generates all the variables (more precisely the columns) from the Hodiny class as private variables for both child classes. Now, when I try to create these tables with app/console doctrine:schema:update --force
, I get errors that $id must be protected or weaker
. When I change this protection manually, I can create tables, but there is only one column (id). But that is not what I was hoping for. Can someone give me some advice on what I'm doing wrong?
source share