Note that there are some explanatory texts on larger screens.

plurals
  1. POReflect MySQL polymorphic association in Doctrine 2.2
    primarykey
    data
    text
    <p>I'm using Doctrine 2.2.0 together with Codeigniter. I'm new to Doctrine (or to ORM in general).</p> <p>I'm setting up entity and proxy classes based on YAML files which works fine. I do have problems in reflecting a polymorphic association in my DB in my Doctrine classes. I'm looking for a concrete example on how to implement the following polymorphic association in Doctrine.</p> <p>In my DB I have a table called products. Depending on the value of field <code>object_type</code> and <code>object_id</code> I want to relate either to a record in the table videos or the table cars (I simplified it here). I want to keep both product types in 2 separate table because one has nothing to do with the other and both tables relate to other tables.</p> <p>I took a look at the Doctrine Inheritance documentation and other examples, but it doesn't seem to help me. <strong>If possible I want to avoid adding the columns <code>description</code> and <code>price</code> to the tables videos and cars</strong>.</p> <p>Many thanks!</p> <pre><code>|Table: products | |-----------------------------------------------------| | ID | description | price | object_type | object_id | |-----------------------------------------------------| | 1 | A video | 20.00 | video | 12 | | 2 | A car | 159.00 | car | 5 | |Table: videos | |--------------------------------------------| | ID | filename | artist_id | date | |--------------------------------------------| | 12 | somename.mp4 | 189 | 2011-02-15 | |Table: cars | |------------------------------| | ID | brand_id | model | year | |------------------------------| | 5 | 17 | astra | 2010 | </code></pre>
    singulars
    1. This table or related slice is empty.
    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