Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine 2 - Access level problems when using Class Table Inheritance
    primarykey
    data
    text
    <p>I'm trying to implent the <a href="http://www.doctrine-project.org/docs/orm/2.0/en/reference/inheritance-mapping.html#class-table-inheritance" rel="nofollow">Class Table Inheritance</a> Doctrine 2 offers in my Symfony 2 project. Let's say a have a <strong>Pizza</strong> class, <strong>Burito</strong> class and a <strong>MacAndCheese</strong> class which all inherit from a <strong><em>Food</em></strong> class.</p> <p>The <strong><em>Food</em></strong> class has the following settings:</p> <pre><code>&lt;?php namespace Kitchen; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="food") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="dish", type="string") * @ORM\DiscriminatorMap({"pizza" = "Pizza", "burito" = "Burito", "mac" =&gt; "MacAndCheese"}) */ class Food { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; </code></pre> <p>And the inherited classes have these settings (<strong>Pizza</strong> for example):</p> <pre><code>&lt;?php namespace Kitchen; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="food_pizza") */ class Pizza extends Food { </code></pre> <p>When running <em>doctrine:schema:update --force</em> from the Symfony 2 app/console I get an error about the access level of <em>$id</em> in the children of <strong><em>Food</em></strong> (<strong>Pizza</strong> for example), stating it must be protected or weaker. I haven't declared <em>$id</em> anywhere in the <strong>Pizza</strong>, since I reckoned it would be inherited from <strong><em>Food</em></strong>.</p> <p>So I tried to declare <em>$id</em>, but that gives me an error, cause I can't redeclare $id. I figure I need some kind of reference to $id from <strong><em>Food</em></strong> in <strong>Pizza</strong>, but the Doctrine 2 documentation didn't really give me a clear answer on what this would look like.</p> <p>Hopefully you understand what I mean and can help me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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