<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed May 22 08:12:43 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/DDC-1666/DDC-1666.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>[DDC-1666] orphanRemoval does not work with oneToOne: Duplicate entry Error</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-1666</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;orphanRemoval does not work with oneToOne.&lt;br/&gt;
Im getting &quot;duplicate entry&quot; errors after replacing the oneToOne object.&lt;br/&gt;
Doctrine seems to insert the new data before removing the old one.&lt;br/&gt;
if i remove the unique constraint by hand in the database it works.&lt;/p&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Mysql Error&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;/*
Error:
SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry &apos;1&apos; &lt;span class=&quot;code-keyword&quot;&gt;for&lt;/span&gt; key &apos;UNIQ_9D8DDB05579B502F&apos;
*/
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Models and YAML Mapping&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;
/*
Contact:
  type: entity
  table: contact
  fields:
    _id:
      id: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      type: integer
      unsigned: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      nullable: &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;
      generator:
        strategy: AUTO
      column: id
  oneToOne:
    _standingData:
      targetEntity: StandingData
      mappedBy: _contact
      cascade: [&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;merge&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;remove&quot;&lt;/span&gt;] 
      orphanRemoval: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
*/

class Contact
{
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $_id;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $_standingData;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function newStandingData(StandingData $sd)
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_standingData = $sd;
        $sd-&amp;gt;setContact($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);
    }
}

/*
StandingData:
  type: entity
  table: standing_data
  fields:
    _id:
      id: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      type: integer
      unsigned: &lt;span class=&quot;code-keyword&quot;&gt;true&lt;/span&gt;
      nullable: &lt;span class=&quot;code-keyword&quot;&gt;false&lt;/span&gt;
      generator:
        strategy: AUTO
      column: id
  oneToOne:
    _contact:
      targetEntity: Contact
      inversedBy: _standingData
      joinColumns:
        contact_id:
          referencedColumnName: id
          onDelete: cascade
*/

class StandingData
{
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $_id;
    &lt;span class=&quot;code-keyword&quot;&gt;private&lt;/span&gt; $_contact;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setContact(Contact $c)
    {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;_contact = $c;
    }
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;


&lt;div class=&quot;code panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;codeHeader panelHeader&quot; style=&quot;border-bottom-width: 1px;&quot;&gt;&lt;b&gt;Script&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;codeContent panelContent&quot;&gt;
&lt;pre class=&quot;code-java&quot;&gt;&lt;span class=&quot;code-comment&quot;&gt;// Create &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Contact
&lt;/span&gt;$contact = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Contact();
$contact-&amp;gt;newStandingData(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \StandingData());
$em-&amp;gt;persist($contact);
$em-&amp;gt;flush();

&lt;span class=&quot;code-comment&quot;&gt;// Try to change StandingData
&lt;/span&gt;$contact-&amp;gt;newStandingData(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; \StandingData());
$em-&amp;gt;flush();


&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="13471">DDC-1666</key>
            <summary>orphanRemoval does not work with oneToOne: Duplicate entry Error</summary>
                <type id="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="3" iconUrl="http://www.doctrine-project.org/jira/images/icons/priorities/major.png">Major</priority>
                    <status id="5" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="gutzuwissen">Mario Knippfeld</reporter>
                        <labels>
                    </labels>
                <created>Thu, 23 Feb 2012 09:31:48 +0000</created>
                <updated>Thu, 14 Mar 2013 22:43:25 +0000</updated>
                    <resolved>Thu, 14 Mar 2013 22:43:25 +0000</resolved>
                            <version>2.2</version>
                                <fixVersion>2.3.3</fixVersion>
                                <component>ORM</component>
                        <due></due>
                    <votes>1</votes>
                        <watches>3</watches>
                        <comments>
                    <comment id="17586" author="beberlei" created="Wed, 14 Mar 2012 21:47:38 +0000"  >&lt;p&gt;This is a necessary restriction for the internals of Doctrine to always work correctly.&lt;/p&gt;</comment>
                    <comment id="17841" author="acasademont" created="Thu, 12 Apr 2012 18:01:04 +0000"  >&lt;p&gt;+1 on this one. So what&apos;s the point of orphanRemoval in OneToOne if it can never be done? Maybe onetoones should not create a unique index but a normal one.&lt;/p&gt;

&lt;p&gt;If it is really a won&apos;t fix, then the docs should reflect that.&lt;/p&gt;</comment>
                    <comment id="17842" author="acasademont" created="Thu, 12 Apr 2012 18:05:18 +0000"  >&lt;p&gt;BTW, as a workaround, i suggest converting this OneToOne case (where the orphanRemoval is in the inverse side) into a ManyToOne so a normal index will be created, not a unique one. Then the new row is inserted fine and the old one is deleted afterwards.&lt;/p&gt;</comment>
                    <comment id="17905" author="gutzuwissen" created="Fri, 4 May 2012 10:39:21 +0000"  >&lt;p&gt;+1&lt;br/&gt;
like Albert said, if its really a wont fix, the docs should state that.&lt;br/&gt;
the example in: &lt;a href=&quot;http://readthedocs.org/docs/doctrine-orm/en/latest/reference/working-with-associations.html?highlight=orphan#orphan-removal&quot; class=&quot;external-link&quot;&gt;http://readthedocs.org/docs/doctrine-orm/en/latest/reference/working-with-associations.html?highlight=orphan#orphan-removal&lt;/a&gt; with a (bidirectional) oneToOne  orphanRemoval association isnt working with mysql and having doctrine created the tables.&lt;br/&gt;
maybe the bidirectional association is the problem?&lt;/p&gt;</comment>
                    <comment id="19527" author="mnapoli" created="Mon, 11 Feb 2013 11:39:04 +0000"  >&lt;p&gt;+1 same for me&lt;/p&gt;

&lt;p&gt;If the example of the docs isn&apos;t supposed to work (i.e. orphanRemoval with oneToOne isn&apos;t supported), then the docs should be updated.&lt;/p&gt;

&lt;p&gt;I can do a PR, but I need you to confirm it&apos;s really the case &lt;a href=&quot;http://www.doctrine-project.org/jira/secure/ViewProfile.jspa?name=beberlei&quot; class=&quot;user-hover&quot; rel=&quot;beberlei&quot;&gt;Benjamin Eberlei&lt;/a&gt;.&lt;/p&gt;</comment>
                    <comment id="19860" author="beberlei" created="Thu, 14 Mar 2013 22:29:00 +0000"  >&lt;p&gt;Its indeed a good fix to disable the unique constraint if orphan removal isset.&lt;/p&gt;</comment>
                    <comment id="19861" author="beberlei" created="Thu, 14 Mar 2013 22:43:25 +0000"  >&lt;p&gt;Fixed and merged into 2.3&lt;/p&gt;

&lt;p&gt;With the change Doctrine will not create unique indexes anymore on Orphan Removal OneToOne associations. You need to change the database schema for this change to take effect essentially.&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>