Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony 2 + Doctrine 2 + inheritance
    text
    copied!<p>I'm searching for a solution for the following problem with a database inheritance using Doctrine 2 built in Symfony 2 framework. This is what I want to do...</p> <p><img src="https://i.stack.imgur.com/EvTRD.png" alt="enter image description here"></p> <p>I want to create two tables (UredniHodiny, KonzultacniHodiny) with the same interface as the abstract class Hodiny. This is how I'm trying to do it</p> <pre><code>&lt;?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; } &lt;?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 { } &lt;?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 { } </code></pre> <p>Now when I run <code>php app/console doctrine:generate:entities CvutPWTImportBundle</code> Symfony generates all variables (more precisely columns) from class Hodiny as private variables to both child classes. Now when I'm trying to create those tables with <code>app/console doctrine:schema:update --force</code> I'm getting errors that <code>$id must be protected or weaker</code>. When I change this protection manually I am able to create tables but there is only one column (id). But this is not what I was hoping for. Can somebody give me any advice what I'm doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload