Note that there are some explanatory texts on larger screens.

plurals
  1. PODoctrine table class inheritance when one subclass has no extra attributes
    text
    copied!<p>I'm having a problem with my mapping. I can't get it to work. I have an abstract base class like so:</p> <pre><code>/** * @Entity * @Table(name="actions") * @InheritanceType("JOINED") * @DiscriminatorColumn(name="type", type="string") * @DiscriminatorMap({"FOO" = "FooAction", "BAR" = "BarAction", ...}) */ abstract class AbstractAction { ... } </code></pre> <p>I have a bunch of different actions, all with different fields. E.g:</p> <pre><code>/** * @Entity * @Table(name="actions_foo") */ class FooAction extends AbstractAction { ... } </code></pre> <p>But one of my actions (<code>BarAction</code>) does not need any extra fields besides those supplied by the <code>AbstractAction</code>. But how can I map that? I tried omitting the <code>@Table</code>, or using the same <code>@Table</code> as the <code>AbstractAction</code>, but to no effect.</p> <pre><code>/** * @Entity * @Table(name="actions") */ class BarAction extends AbstractAction { ... } </code></pre> <p>Omitting the <code>@Table</code> gives me a <code>PDOException</code> about a missing table <code>BarAction</code>. Using the <code>@Table</code> of the base class gives me:</p> <pre><code>PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens </code></pre> <p>So, how do I map this? </p> <p><strong>Edit:</strong> So far I have tried two more things.</p> <p>I tried removing the <code>@Entity</code> as well as the <code>@Table</code> from <code>BarAction</code> in the hope that this way it would no longer require a database table. That doesn't work. Instead, I get this error:</p> <pre><code>Doctrine\ORM\Mapping\MappingException: Class BarAction is not a valid entity or mapped super class. </code></pre> <p>Next I tried creating an <code>actions_bar</code> table in my database with just a single foreign key column <code>id</code>. Then I mapped the <code>BarAction</code> to it. That works (yay!) but it feels crufty and ugly to have an extra SQL table that I don't need at all.</p> <p>So, still looking for a better way...</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