Note that there are some explanatory texts on larger screens.

plurals
  1. POMany-to-One - Symfony doesn't generate proper ID-based relation
    primarykey
    data
    text
    <p><code>Tag</code> table has a relation to the <code>Category</code> table as Many-to-One (many tags are related to one category, or one category has many tags).</p> <p>I should get normal Many-to-One relation from table <code>Tag</code> to the table <code>Category</code>. It should be based on the ID from the table <code>Category</code> (which is named <code>id_category</code>). However, instead I'm getting... a <code>VARCHAR(255)</code> column in table <code>Tag</code>!</p> <p>Here's part of code from Tag entity:</p> <pre><code>/** * @ORM\Column(nullable=true) * @ORM\ManyToOne(targetEntity="Category") * @ORM\JoinColumn(name="id_category", referencedColumnName="id_category") */ protected $category; </code></pre> <p>Category entity doesn't have appropriate related "tag" column, because it's uni-directional relation. Anyway, here's how <code>id_category</code> is declared in the <code>Category</code> entity (though I don't think it's important):</p> <pre><code>/** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id_category; </code></pre> <p>The result I'm getting by the Doctrine2's command <code>update --dump-sql</code> is the following:</p> <pre class="lang-sql prettyprint-override"><code>ALTER TABLE Tag ADD category VARCHAR(255) DEFAULT NULL </code></pre> <p>Doctrine gives me <code>VARCHAR</code>, instead of <code>INTEGER</code> as id with foreign key. Does anyone know why?<br> How to <em>tell</em> Symfony to make a relation in this case?</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