<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sat May 18 23:15:02 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-2200/DDC-2200.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-2200] Duplicates returned while accessing associations from @PostPersist callback</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-2200</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;When creating a new Post and adding it to a collection in an &lt;b&gt;existing&lt;/b&gt; Thread (i.e. loaded from the database), referencing Thread&apos;s posts collection in Post&apos;s @PostPersist callback returns the Post twice. To clarify, this only happens when Thread was previously persisted. If I&apos;m creating a new Thread object the code works as expected. I&apos;ve included some sample code to better illustrate my issue.&lt;/p&gt;

&lt;p&gt;I don&apos;t know if this is a bug, or if I&apos;m doing something that I shouldn&apos;t be, but I couldn&apos;t find this limitation mentioned in the documentation, and this seems to go against the expected behavior.&lt;/p&gt;

&lt;p&gt;Here are my sample entities:&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;

/**
 * @Entity
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;thread&quot;&lt;/span&gt;)
 */
class &lt;span class=&quot;code-object&quot;&gt;Thread&lt;/span&gt;
{
    /** 
     * @Id
     * @GeneratedValue
     * @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $id;

    /** 
     * @OneToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Post&quot;&lt;/span&gt;, mappedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;thread&quot;&lt;/span&gt;, cascade={&lt;span class=&quot;code-quote&quot;&gt;&quot;persist&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;remove&quot;&lt;/span&gt;})
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $posts;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function __construct() {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;posts = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; ArrayCollection();
    }   

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getPosts() {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;posts-&amp;gt;toArray();
    }   

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function addPost(Post $post) {
        $post-&amp;gt;setThread($&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;);
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;posts-&amp;gt;add($post);
    }   
}

/**
 * @Entity
 * @Table(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;post&quot;&lt;/span&gt;)
 * @HasLifecycleCallbacks
 */
class Post
{
    /** 
     * @Id
     * @GeneratedValue
     * @Column(type=&lt;span class=&quot;code-quote&quot;&gt;&quot;integer&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $id;

    /** 
     * @ManyToOne(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;&lt;span class=&quot;code-object&quot;&gt;Thread&lt;/span&gt;&quot;&lt;/span&gt;, inversedBy=&lt;span class=&quot;code-quote&quot;&gt;&quot;posts&quot;&lt;/span&gt;)
     * @JoinColumn(name=&lt;span class=&quot;code-quote&quot;&gt;&quot;thread_id&quot;&lt;/span&gt;, referencedColumnName=&lt;span class=&quot;code-quote&quot;&gt;&quot;id&quot;&lt;/span&gt;)
     */
    &lt;span class=&quot;code-keyword&quot;&gt;protected&lt;/span&gt; $thread;

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function getId() {
        &lt;span class=&quot;code-keyword&quot;&gt;return&lt;/span&gt; $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;id;
    }   

    /** 
     * @PostPersist
     */
    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function onPostPersist() {
        $posts = $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;thread-&amp;gt;getPosts();
        foreach ($posts as $post) {
            echo &apos;id: &apos; . $post-&amp;gt;getId() . &apos; type: &apos; . get_class($alert) . &apos;&amp;lt;br /&amp;gt;&apos;;
        }   
    }

    &lt;span class=&quot;code-keyword&quot;&gt;public&lt;/span&gt; function setThread(&lt;span class=&quot;code-object&quot;&gt;Thread&lt;/span&gt; $thread) {
        $&lt;span class=&quot;code-keyword&quot;&gt;this&lt;/span&gt;-&amp;gt;thread = $thread;
    }   
}

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And the calling code:&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-comment&quot;&gt;// Grab an existing thread.
&lt;/span&gt;$thread = $em-&amp;gt;getReference(&apos;&lt;span class=&quot;code-object&quot;&gt;Thread&lt;/span&gt;&apos;, 1); 
$thread-&amp;gt;addPost(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Post());
$em-&amp;gt;flush();

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This outputs:&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;

id: 1 type: Post
id: 1 type: Post

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Alternatively:&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-comment&quot;&gt;// Create a &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; thread.
&lt;/span&gt;$thread = &lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;code-object&quot;&gt;Thread&lt;/span&gt;()
$thread-&amp;gt;addPost(&lt;span class=&quot;code-keyword&quot;&gt;new&lt;/span&gt; Post());
$em-&amp;gt;persist($thread);
$em-&amp;gt;flush();

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This outputs:&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;

id: 1 type: Post

&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</description>
                <environment></environment>
            <key id="14313">DDC-2200</key>
            <summary>Duplicates returned while accessing associations from @PostPersist callback</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="1" iconUrl="http://www.doctrine-project.org/jira/images/icons/statuses/open.png">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                    <security id="10000">All</security>
                        <assignee username="beberlei">Benjamin Eberlei</assignee>
                                <reporter username="breathe">Brent</reporter>
                        <labels>
                    </labels>
                <created>Sat, 15 Dec 2012 02:06:07 +0000</created>
                <updated>Sat, 15 Dec 2012 02:06:07 +0000</updated>
                                    <version>2.3.1</version>
                                                <component>ORM</component>
                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>