Note that there are some explanatory texts on larger screens.

plurals
  1. POSymfony2 ORM FK Composite
    primarykey
    data
    text
    <p>I'm new with Symfony2 and Doctrine 2 ORM, then i got a problem with composite FK association.</p> <p>While the association OneToMany-ManyToOne by a single auto-increment ID works good, i got many troubles with the same kind of association but through a composite PK.</p> <p>What i would like to do is an entity-structure that mirrors the below shema.</p> <p><a href="http://imageshack.us/photo/my-images/9/z07m.jpg" rel="nofollow">http://imageshack.us/photo/my-images/9/z07m.jpg</a> (Sorry but I cannot insert images into the post)</p> <p>where</p> <pre><code>prd_product_data.product_id prd_product_data.language_id </code></pre> <p>make up together the PK of 'prd_product_data' and</p> <pre><code>prd_product_image.pdoduct_id prd_product_image.language_id </code></pre> <p>make up the FK linked to the table 'prd_product_data'.</p> <p>These below</p> <pre><code>prd_product_image.pdoduct_id prd_product_image.language_id prd_product_image.file_image_id </code></pre> <p>make up, all together, the PK of 'prd_product_image'.</p> <p>I read that Doctrine 2.1 and up, supports natively the composed PK - FK association but there are very few examples. Moreover, surfing on the web, i found just scattered fragments of similar situations but nothing of useful. The main issue now, is that i'm unable to create one unique object for the two ids, like such an unique id.</p> <p>For example...</p> <p>Snapshot for the Entity <strong>ProductData</strong> where "<em>product</em> and <em>language</em> should make up the same object:</p> <pre><code>/** * * @ORM\OneToMany(targetEntity="ProductImage", mappedBy="product") */ protected $products_Pimgs; /** * * @ORM\OneToMany(targetEntity="ProductImage", mappedBy="language") */ protected $products_Limgs; </code></pre> <p>Snapshot for the Entity <strong>ProductImage</strong> where *product_id* and *language_id* made up the FK for the entity ProductData:</p> <pre><code> /** * * @ORM\Id * @ORM\ManyToOne(targetEntity="ProductData", inversedBy="products_Pimgs") * @ORM\JoinColumn(name="product_id", referencedColumnName="product_id") */ protected $product; /** * * @ORM\Id * @ORM\ManyToOne(targetEntity="ProductData", inversedBy="products_Limgs") * @ORM\JoinColumn(name="language_id", referencedColumnName="language_id") */ protected $language; /** * * @ORM\Id * @ORM\ManyToOne(targetEntity="FileImage", inversedBy="files_images") * @ORM\JoinColumn(name="file_image_id", referencedColumnName="id") */ protected $file_image; </code></pre> <p>From these snapshots it's evident that those keys are working separately.</p> <p>In the end, this is my doctrine version, taken from the composer:</p> <pre><code>"doctrine/orm": "&gt;=2.2.3,&lt;2.4-dev", </code></pre> <p>How can i create an unique reference with two objects with ORM?</p>
    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.
    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