<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Wed Jun 19 12:46:54 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-117/DDC-117.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-117] Allow @Id on @ManyToOne fields</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-117</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;Sometimes, a @ManyToOne field has to be the Primary Key, or part of the Primary Key. Adding @Id to the @ManyToOne does not help, an additional property with duplicates the referenced id is needed:&lt;/p&gt;

&lt;p&gt;(userId and User field in the Phonenumber class - to be able to set @Id on userId):&lt;br/&gt;
&lt;a href=&quot;http://pastebin.com/d51e021e2&quot; class=&quot;external-link&quot;&gt;http://pastebin.com/d51e021e2&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Allowing @Id on @ManyToOne fields (which would make the JoinColumn a PK) would help here. Any maybe this would also fix &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-116&quot; title=&quot;array_combine error when using combined Primary Key&quot;&gt;&lt;del&gt;DDC-116&lt;/del&gt;&lt;/a&gt;&lt;/p&gt;</description>
                <environment></environment>
            <key id="10344">DDC-117</key>
            <summary>Allow @Id on @ManyToOne fields</summary>
                <type id="2" iconUrl="http://www.doctrine-project.org/jira/images/icons/issuetypes/newfeature.png">New Feature</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="nicokaiser">Nico Kaiser</reporter>
                        <labels>
                    </labels>
                <created>Thu, 5 Nov 2009 09:19:06 +0000</created>
                <updated>Sun, 9 Jan 2011 15:10:40 +0000</updated>
                    <resolved>Sun, 2 Jan 2011 06:04:58 +0000</resolved>
                            <version>2.0-ALPHA3</version>
                                <fixVersion>2.1</fixVersion>
                                        <due></due>
                    <votes>8</votes>
                        <watches>11</watches>
                        <comments>
                    <comment id="11039" author="nicokaiser" created="Mon, 7 Dec 2009 13:09:23 +0000"  >&lt;p&gt;Thanks for your reply on doctrine-user!&lt;/p&gt;

&lt;p&gt;My previous workaround was something like this:&lt;br/&gt;
&lt;a href=&quot;http://pastie.org/private/uoawwvf75onnvph8bj1fwg&quot; class=&quot;external-link&quot;&gt;http://pastie.org/private/uoawwvf75onnvph8bj1fwg&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Instead of just having a $User property in the Phonenumber entity (which is mapped by the userId field in the phonenumber table), I have an additional $userId property, which is also mapped to the userId DB field. This way I could make $userId @Id (and thus add it to the PKs), but I had to manually update it when I set the $User (see the TODO annotations in the Pastie code).&lt;/p&gt;

&lt;p&gt;I see &quot;EntityManager#find(...)&quot; would have to be able to also get objects as identifiers, e.g. (int, User), which may have major implications... &lt;/p&gt;


&lt;p&gt;However I think to support constructions like this is very important as it&apos;s a very common pattern, especially for OneToOne associations with no additional identifier field (PK = FK)... &lt;/p&gt;</comment>
                    <comment id="11219" author="romanb" created="Thu, 17 Dec 2009 20:35:50 +0000"  >&lt;p&gt;We might need to introduce the concept of an IdClass for this in order to be implemented decently.&lt;/p&gt;</comment>
                    <comment id="13321" author="mstoehr" created="Tue, 15 Jun 2010 06:09:03 +0000"  >&lt;p&gt;I just ran into this exact issue. Is there any decent way to work around this issue as the pastie.org-Link is already gone?&lt;/p&gt;</comment>
                    <comment id="13323" author="nicokaiser" created="Tue, 15 Jun 2010 06:44:33 +0000"  >&lt;p&gt;In an Entity (e.g. &quot;Phonenumber&quot;) with PrimaryKey userId you can do something like this:&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;/**
 * @ManyToOne(targetEntity=&quot;Entities\User&quot;, inversedBy=&quot;Phonenumbers&quot;)
 * @JoinColumn(name=&quot;userId&quot;, referencedColumnName=&quot;id&quot;)
 */
protected $User;

/**
 * @Id
 * @Column(name=&quot;userId&quot;, type=&quot;integer&quot;)
 */
protected $userId;

public function setUser(\Entities\User $user)
{
    $this-&amp;gt;User = $user;
    $this-&amp;gt;userId = $user-&amp;gt;getId();
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13830" author="beberlei" created="Sat, 7 Aug 2010 14:10:01 +0000"  >&lt;p&gt;I took the time today and tried what is possible to hack in this regard and came up with a pretty trivial solution for this. This is a very early draft of this functionality as it might be included in 2.1&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://github.com/doctrine/doctrine2/commits/DDC-117&quot; class=&quot;external-link&quot;&gt;http://github.com/doctrine/doctrine2/commits/DDC-117&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;What works?&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Association Only Composite Primary Keys (Reference with SourceArticle to TargetArticle)&lt;/li&gt;
	&lt;li&gt;Mixed Composite Primary Keys (ArticleTranslation with Article + Language)&lt;/li&gt;
	&lt;li&gt;Single Association Primary Keys (Article and ArticleDetails)&lt;/li&gt;
&lt;/ul&gt;
</comment>
                    <comment id="13831" author="mstoehr" created="Sat, 7 Aug 2010 14:16:19 +0000"  >&lt;p&gt;Wow, great work, Benjamin. Will try it out ASAP and when it works, I&apos;ll owe you a beer. &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;/p&gt;</comment>
                    <comment id="13867" author="s9e" created="Sun, 8 Aug 2010 18:36:10 +0000"  >&lt;p&gt;I&apos;m having troubles with user-defined column names used in SAPK. The schema tool complains that the column name doesn&apos;t exist. I&apos;ve reduced it to a small testcase based on DDC117Test.&lt;/p&gt;</comment>
                    <comment id="13868" author="s9e" created="Sun, 8 Aug 2010 18:36:46 +0000"  >&lt;p&gt;SAPK with user-defined column names&lt;/p&gt;</comment>
                    <comment id="13948" author="beberlei" created="Sun, 15 Aug 2010 13:00:05 +0000"  >&lt;p&gt;I fixed another bunch of issues with hydration and updating of assoc-id entities.&lt;/p&gt;

&lt;p&gt;@s9e i will now tackle your issue.&lt;/p&gt;</comment>
                    <comment id="13949" author="beberlei" created="Sun, 15 Aug 2010 13:16:26 +0000"  >&lt;p&gt;@s9e you forgot to define the @JoinColumn annotation correctly. that is necessary when you rename the ID column on the other side. See my current commit, it works for me!&lt;/p&gt;

&lt;p&gt;The commit is: &lt;a href=&quot;http://github.com/doctrine/doctrine2/commit/772e5924898326de2c769c4cb0c6874fde4edc45&quot; class=&quot;external-link&quot;&gt;http://github.com/doctrine/doctrine2/commit/772e5924898326de2c769c4cb0c6874fde4edc45&lt;/a&gt;&lt;/p&gt;</comment>
                    <comment id="13956" author="beberlei" created="Sun, 15 Aug 2010 14:21:13 +0000"  >&lt;p&gt;Add current version of the patch diffed against the master from today, for easier testing and review.&lt;/p&gt;</comment>
                    <comment id="13960" author="s9e" created="Sun, 15 Aug 2010 18:18:27 +0000"  >&lt;p&gt;@Benjamin Eberlei - Actually it&apos;s the other way around. I have defined @JoinColumn on both sides of the relationship, and SchemaTool doesn&apos;t like that. After removing @JoinColumn from the inverse side, SchemaTool processes the entities as expected, so I&apos;m not sure whether it should be considered a bug or a feature. If @JoinColumn should only be defined on the owning side, please add a note to the manual.&lt;/p&gt;

&lt;p&gt;Anyway, the schema now works but I&apos;m still having troubles persisting through cascade. Test attached.&lt;/p&gt;</comment>
                    <comment id="13961" author="beberlei" created="Mon, 16 Aug 2010 03:21:45 +0000"  >&lt;p&gt;the @joinColumn is explained in the association mapping chapter. There are examples for each cases, showing where to put the annotation and where not.&lt;/p&gt;

&lt;p&gt;The Persist Cascade i pick up next then.&lt;/p&gt;</comment>
                    <comment id="13973" author="mjh_ca" created="Tue, 17 Aug 2010 07:07:00 +0000"  >&lt;p&gt;Hi Benjamin, great work on this.  Testing it out now.  One problem (do you want a ticket opened?).  Using the latest &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt; branch, schema tool crates both a PRIMARY KEY and a UNIQUE KEY (at least in MySQL) on the same columns.  The UNIQUE KEY is really not necessary, right?&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;/** @Entity */
class Foo {
    /**
     * @Id @Column(type=&quot;integer&quot;)
     * @GeneratedValue
     */
    protected $id;
}

/** @Entity */
class Bar {
    /**
     * @Id
     * @OneToOne(targetEntity=&quot;Foo&quot;)
     * @JoinColumn(name=&quot;foo_id&quot;, referencedColumnName=&quot;id&quot;)
     */
    protected $fooId;
}
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Produces:&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;CREATE TABLE Bar (foo_id INT NOT NULL, UNIQUE INDEX Bar_foo_id_uniq (foo_id), PRIMARY KEY(foo_id)) ENGINE = InnoDB;
CREATE TABLE Foo (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Expected:&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;CREATE TABLE Bar (foo_id INT NOT NULL, PRIMARY KEY(foo_id)) ENGINE = InnoDB;
CREATE TABLE Foo (id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="13974" author="beberlei" created="Tue, 17 Aug 2010 07:14:22 +0000"  >&lt;p&gt;No, all the issues on this ticket. I branch them into subtickets if necessary.&lt;/p&gt;</comment>
                    <comment id="14730" author="mjh_ca" created="Sun, 14 Nov 2010 05:12:16 +0000"  >&lt;p&gt;Hi Benjamin - would you mind doing a merge from current master to &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt; branch?  Been using it for devel and it is working quite well but commit 140ddf5098a7ffdf6bc3 on Sept 27 causes a merge conflict.  Looks like it is easy to resolve but it would be great if it could be merged into your &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt; so extra steps aren&apos;t required to clone/checkout &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-117&quot; title=&quot;Allow @Id on @ManyToOne fields&quot;&gt;&lt;del&gt;DDC-117&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</comment>
                    <comment id="15045" author="beberlei" created="Tue, 28 Dec 2010 11:29:06 +0000"  >&lt;p&gt;I updated the branch to integrate with the current master and attached a new patch to the ticket.&lt;/p&gt;</comment>
                    <comment id="15046" author="beberlei" created="Tue, 28 Dec 2010 12:01:35 +0000"  >&lt;p&gt;@S9e: Yes this is obvious, it works only with Sequence as ID Generation strategy (for example with PostgreSQL)&lt;/p&gt;

&lt;p&gt;The problem is, during persist MySQL and SQLite don&apos;t know the value of the primary key yet. However for the @id + @ManyToOne patch to work it is necessary that all the dependencies primary keys are already known. That is why two step flush procedures are sometimes necessary.&lt;/p&gt;

&lt;p&gt;1. persist non fk+pk entities and flush them&lt;br/&gt;
2. persist fk+pk entities then flush them&lt;/p&gt;</comment>
                    <comment id="15082" author="beberlei" created="Sat, 1 Jan 2011 15:49:03 +0000"  >&lt;p&gt;Patch is now finished and will be merged into master tomorrow.&lt;/p&gt;</comment>
                    <comment id="15095" author="beberlei" created="Sun, 2 Jan 2011 06:04:58 +0000"  >&lt;p&gt;Merged into master and scheduled for 2.1.&lt;/p&gt;

&lt;p&gt;Please test this patch extensively, there are tons of examples in tests/Doctrine/Tests/Models/DDC117 and tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php&lt;/p&gt;</comment>
                    <comment id="15115" author="henrikbjorn" created="Sun, 9 Jan 2011 12:05:40 +0000"  >&lt;p&gt;@Benjamin&lt;/p&gt;

&lt;p&gt;I have created a OneToOne relation on a User -&amp;gt; Profile where the profile is specified as the inverse side so i can have user_id be the primary key. And it all works as expected except that when i create a new User (The Profile object is getting created in the user constructor) and persist it (the relation have cascade-all specified)  i end up with the error &quot;The given entity has no identity.&quot;. But if i persist the user without creating the profile inside it and fliush and then create a Profile object and persist and flush that it all work.&lt;/p&gt;

&lt;p&gt;It seems like it dosent know that the User should be saved first so that it have an id and then save the profile. Dont know if this is a bug or it is expected behavior.&lt;/p&gt;</comment>
                    <comment id="15116" author="beberlei" created="Sun, 9 Jan 2011 15:10:40 +0000"  >&lt;p&gt;expected behavior, you are using the id generator &quot;assigned&quot; which means on persist the id has to be assigned. In your case it isnt, because the related object has not been assigned an id itself, thus failing.&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                                <inwardlinks description="is duplicated by">
                            <issuelink>
            <issuekey id="11898">DDC-795</issuekey>
        </issuelink>
                    </inwardlinks>
                            </issuelinktype>
                    </issuelinks>
                <attachments>
                    <attachment id="10902" name="ddc117-20101228.diff" size="28758" author="beberlei" created="Tue, 28 Dec 2010 11:29:06 +0000" />
                    <attachment id="10742" name="ddc117test_cascade_persist.patch" size="1173" author="s9e" created="Sun, 15 Aug 2010 18:18:43 +0000" />
                    <attachment id="10741" name="ddc117_20100815.patch" size="29539" author="beberlei" created="Sun, 15 Aug 2010 14:21:13 +0000" />
                </attachments>
            <subtasks>
            <subtask id="11559">DDC-658</subtask>
            <subtask id="11898">DDC-795</subtask>
            <subtask id="12121">DDC-881</subtask>
            <subtask id="12212">DDC-922</subtask>
        </subtasks>
        </item>
</channel>
</rss>