<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Mon May 20 01:12:09 UTC 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.doctrine-project.org/jira/si/jira.issueviews:issue-xml/DBAL-394/DBAL-394.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Doctrine Project</title>
    <link>http://www.doctrine-project.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.7</version>
        <build-number>850</build-number>
        <build-date>21-02-2013</build-date>
    </build-info>

<item>
            <title>[DBAL-394] Unsigned integers are not respected by the schema tool for assocations</title>
                <link>http://www.doctrine-project.org/jira/browse/DBAL-394</link>
                <project id="10040" key="DBAL">Doctrine DBAL</project>
                        <description>&lt;p&gt;Before commenting, I&apos;ve done so much debugging and searching into this issue and if I missed something major, I apologise.&lt;/p&gt;

&lt;p&gt;From what I understand, the ORM doesn&apos;t care about unsigned. That&apos;s fair enough. That leaves it to DBAL to handle it.&lt;/p&gt;

&lt;p&gt;However, it&apos;s not possible to successfully use something like the following table without having the schema manager complain.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
CREATE TABLE `account` (
  `id` &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(10) unsigned NOT NULL AUTO_INCREMENT COMMENT &apos;(DC2Type:unsigned_integer)&apos;,
  `user_id` &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;(10) unsigned DEFAULT NULL COMMENT &apos;(DC2Type:unsigned_integer)&apos;,
  PRIMARY KEY (`id`),
  KEY `IDX_7D3656A461220EA6` (`user_id`)
) ENGINE=InnoDB
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In that code, I&apos;m using a custom type &quot;unsigned_integer&quot; that extends the DBAL integer type with this:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        $fieldDeclaration[&apos;unsigned&apos;] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;

        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $platform-&amp;gt;getIntegerTypeDeclarationSQL($fieldDeclaration);
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The reason for this is because the ORM won&apos;t map unsigned ints for me. Combined with this is an event listener for the class metadata. Something like this:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
    /**
     * Maps additional metadata.
     *
     * Specifically, &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; there exist an unsigned integer field, attach the
     * &lt;span class=&quot;code-quote&quot;&gt;&quot;unsigned&quot;&lt;/span&gt; option to it. This is required because the Doctrine ORM does
     * not &lt;span class=&quot;code-keyword&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; and we are using &lt;span class=&quot;code-quote&quot;&gt;&quot;UNSIGNED INT&quot;&lt;/span&gt;s in our MySQL columns.
     * Without &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;. the Doctrine Schema Tool will complain about column
     * differences.
     *
     * Note: there is no performance impact in doing &lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt; because the class
     * metadata should be cached after the first request.
     *
     * @param LoadClassMetadataEventArgs $eventArgs
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
    {
        foreach ($eventArgs-&amp;gt;getClassMetadata()-&amp;gt;fieldMappings as &amp;amp;$mapping) {
            &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (isset($mapping[&apos;type&apos;]) &amp;amp;&amp;amp; UnsignedIntegerType::UNSIGNED_INTEGER === $mapping[&apos;type&apos;]) {
                &lt;span class=&quot;code-keyword&quot;&gt;if&lt;/span&gt; (!isset($mapping[&apos;options&apos;])) {
                    $mapping[&apos;options&apos;] = array();
                }

                $mapping[&apos;options&apos;][&apos;unsigned&apos;] = &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;;
            }
        }
    }
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now, in the example table above, the schema tool will honour the &quot;id&quot; column, however it won&apos;t honour the association join column no matter what I do. My attempts include adding an event listener for class meta data as above (basically tricking the ORM) and also adding an event listener for the schema events.&lt;/p&gt;

&lt;p&gt;The other day on GitHub there was a commit (&lt;a href=&quot;https://github.com/doctrine/doctrine2/commit/a27be2fab61b1cfde4d2ecbc729a4a68816fca76&quot; class=&quot;external-link&quot;&gt;https://github.com/doctrine/doctrine2/commit/a27be2fab61b1cfde4d2ecbc729a4a68816fca76&lt;/a&gt;) to help with this, but it&apos;s still not all working.&lt;/p&gt;

&lt;p&gt;Also, comments and issues on the Jira tracker have said how there&apos;s legacy code related to &quot;unsigned&quot; and &quot;default&quot;, but I can&apos;t tell what&apos;s legacy and what&apos;s allowed, especially when there&apos;s a commit like that one above.&lt;/p&gt;

&lt;p&gt;By the way, I have found that the simple unsigned field mapping works. E.g.:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
    fields:
        counter:
            type: integer
            column: counter
            options:
                unsigned: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If it helps at all, here&apos;s the YAML mapping file for the above table/entity:&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
Account:
    type: entity
    table: account
    id:
        id:
            type: unsigned_integer
            generator:
                strategy: AUTO
    manyToOne:
        creator:
            targetEntity: User
            joinColumn:
                name: user_id
                referencedColumnName: id # Note: user table id is also unsigned_integer
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Is it possible to 1) fix this or 2) let me know if I&apos;m just doing something wrong?&lt;/p&gt;

&lt;p&gt;Note: as I said above, I know that Doctrine DBAL and ORM does not care so much for unsigned ints because of portability, etc. but it seems that because of that commit above (24 days ago), there&apos;s a half-implememented/legacy solution going on here.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br/&gt;
Jon&lt;/p&gt;</description>
                <environment></environment>
            <key id="14284">DBAL-394</key>
            <summary>Unsigned integers are not respected by the schema tool for assocations</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="4" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/minor.png">Minor</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                                <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="jonathaningram">Jonathan Ingram</reporter>
                        <labels>
                    </labels>
                <created>Fri, 30 Nov 2012 04:54:20 +0000</created>
                <updated>Fri, 3 May 2013 14:37:41 +0000</updated>
                    <resolved>Wed, 1 May 2013 18:45:46 +0000</resolved>
                            <version>2.3</version>
                                                <component>Schema Managers</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>4</watches>
                        <comments>
                    <comment id="20178" author="beberlei" created="Wed, 1 May 2013 18:45:46 +0000"  >&lt;p&gt;This was fixed in 657a54da&lt;/p&gt;</comment>
                    <comment id="20191" author="naelyth" created="Fri, 3 May 2013 07:24:32 +0000"  >&lt;p&gt;This was not fixed. We can use the option &quot;unsigned&quot; for the fields but not the id.&lt;/p&gt;

&lt;p&gt;If someone has a solution or if you can fix this, that would be really cool !&lt;/p&gt;</comment>
                    <comment id="20198" author="naelyth" created="Fri, 3 May 2013 14:37:41 +0000"  >&lt;p&gt;After some research with a co-worker we&apos;ve found a solution to our little problem.&lt;/p&gt;

&lt;p&gt;To fix this you just have to add these lines in the YamlDriver (Doctrine/ORM/Mapping/Driver/YamlDriver.php) in the function &quot;loadMetadataForClass&quot;, line 265 in the 2.3.3 version of Doctrine ORM :&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;if (isset($idElement[&apos;options&apos;])) {
   $mapping[&apos;options&apos;] = $idElement[&apos;options&apos;];
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Just before the :&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;$metadata-&amp;gt;mapField($mapping);
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And that an example of schema :&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;Entities\Test:
  type: entity
  table: Test
  id:
    id:
      type: integer
      options:
        unsigned: true
      generator:
        strategy: AUTO
  fields:
    testField:
      type: smallint
      options:
        unsigned: true
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this, the id can be unsigned without using special type of column, and yes just with this little if &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/wink.gif&quot; height=&quot;20&quot; width=&quot;20&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;br/&gt;
It has been tested in more complexes schemas and all is going well.&lt;/p&gt;

&lt;p&gt;In fact, maybe it could be interesting to use the function &quot;columnToArray&quot; like it&apos;s used for the other fields.&lt;br/&gt;
In the two cases you must care about what you put in your &quot;options&quot; section.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>