Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For my part I believe I've already ran into some issues with a very basic database schema containing a table which primary key is composed of 2 foreign keys:</p> <p><img src="https://i.stack.imgur.com/UE0Df.png" alt="enter image description here"> </p> <p><strong>When I generate my models, the entity corresponding to the <code>product_i18n</code> entity isn't created</strong>:</p> <pre><code>$ php doctrine-module.php orm:convert-mapping --namespace="Dbi\Entity\\" \ --from-database --force annotation module/Dbi/src/ Processing entity "Dbi\Entity\Locale" Processing entity "Dbi\Entity\Product" $ php doctrine-module.php orm:generate-entities --generate-annotations=1 \ module/Dbi/src Processing entity "Dbi\Entity\Locale" Processing entity "Dbi\Entity\Product" </code></pre> <p>Yet, I believe my <a href="http://pastebin.com/Lhiw7Zpd" rel="nofollow noreferrer">database schema</a> was properly created:</p> <pre><code> PRIMARY KEY (`product_id`, `locale_id`) , INDEX `fk_product_i18n_locale` (`locale_id` ASC) , INDEX `fk_product_i18n_product` (`product_id` ASC) , CONSTRAINT `fk_product_i18n_locale` FOREIGN KEY (`locale_id` ) REFERENCES `mydb`.`locale` (`id` ), CONSTRAINT `fk_product_i18n_product` FOREIGN KEY (`product_id` ) REFERENCES `mydb`.`product` (`id` ) </code></pre> <p>Also, <code>Doctrine 2</code>'s <code>Schema Manager</code> shows that Doctrine seems to understand that relation perfectly (<code>var_dump</code> output altered to make it more concise: removing things such as <code>array</code>, <code>RECURSION</code>, <code>string</code>...):</p> <pre><code>$em = $this-&gt;getServiceLocator()-&gt;get('doctrine.entitymanager.orm_default'); $sm = $em-&gt;getConnection()-&gt;getSchemaManager(); var_dump($sm-&gt;-&gt;listTables()); object(Doctrine\DBAL\Schema\Table)#290 (10) { ["_name":protected]=&gt; "product_i18n" ["_indexes":protected]=&gt; ["primary"]=&gt; ["_columns":protected]=&gt; [0]=&gt; "product_id" [1]=&gt; "locale_id" ["_fkConstraints":protected]=&gt; ["fk_product_i18n_locale"]=&gt; object(Doctrine\DBAL\Schema\ForeignKeyConstraint)#285 (9) { ["_localColumnNames":protected]=&gt; "locale_id" ["_foreignTableName":protected]=&gt; "locale" ["_foreignColumnNames":protected]=&gt; "id" ["fk_product_i18n_product"]=&gt; object(Doctrine\DBAL\Schema\ForeignKeyConstraint)#286 (9) { ["_localColumnNames":protected]=&gt; "product_id" ["_foreignTableName":protected]=&gt; "product" ["_foreignColumnNames":protected]=&gt; "id" </code></pre> <p>Therefore I'm in a situation whereby I can query the schema for the <code>product_i18n</code> table, but can't interact with that table because the corresponding entity model wasn't generated.</p> <p><strong>UPDATE:</strong> as <code>user1136666</code> pointed out: the <a href="http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/limitations-and-known-issues.html" rel="nofollow noreferrer">known issues and limitations page</a> odes state the following:</p> <blockquote> <p>Although we state that we support composite primary keys that does not currently include foreign keys as primary key columns.</p> </blockquote> <p>The workaround is to define a surrogate key and add a unique constraint on the foreign keys, like so:</p> <pre><code>CREATE TABLE IF NOT EXISTS `mydb`.`product_i18n` ( `id` INT NOT NULL AUTO_INCREMENT , `name` VARCHAR(45) NULL , `description` TEXT NULL , `created_at` DATETIME NULL , `modified_at` DATETIME NULL , `product_id` INT NOT NULL , `locale_id` INT NOT NULL , INDEX `fk_product_i18n_locale` (`locale_id` ASC) , INDEX `fk_product_i18n_product` (`product_id` ASC) , PRIMARY KEY (`id`) , UNIQUE (`locale_id` , `product_id`), CONSTRAINT `fk_product_i18n_locale` FOREIGN KEY (`locale_id` ) REFERENCES `mydb`.`locale` (`id` ) CONSTRAINT `fk_product_i18n_product` FOREIGN KEY (`product_id` ) REFERENCES `mydb`.`product` (`id` ) ENGINE = InnoDB; </code></pre> <p><strong>Feature request: <a href="http://www.doctrine-project.org/jira/browse/DDC-1926" rel="nofollow noreferrer">http://www.doctrine-project.org/jira/browse/DDC-1926</a></strong></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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