<!-- 
RSS generated by JIRA (5.2.7#850-sha1:b2af0c8dc8537b36121c6a579fabbdf79fc919e5) at Sun May 19 03:21: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-213/DDC-213.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-213] Persist order of collections</title>
                <link>http://www.doctrine-project.org/jira/browse/DDC-213</link>
                <project id="10032" key="DDC">Doctrine 2 - ORM</project>
                        <description>&lt;p&gt;A Collection is like a php array, an ordered map. Hence there should be the possibility to persist this order.&lt;/p&gt;</description>
                <environment></environment>
            <key id="10620">DDC-213</key>
            <summary>Persist order of collections</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="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="romanb">Roman S. Borschel</assignee>
                                <reporter username="romanb">Roman S. Borschel</reporter>
                        <labels>
                    </labels>
                <created>Tue, 15 Dec 2009 17:40:38 +0000</created>
                <updated>Tue, 16 Oct 2012 07:43:02 +0000</updated>
                                    <version>2.0</version>
                                <fixVersion>2.x</fixVersion>
                                        <due></due>
                    <votes>10</votes>
                        <watches>8</watches>
                        <comments>
                    <comment id="13042" author="shurakai" created="Fri, 21 May 2010 19:50:28 +0000"  >&lt;p&gt;Roman, I&apos;d like to do this one as I have currently a use case for this. Do you have any idea of how to do this? What I&apos;m wondering is whether it is possible to implement this without user intervention. (This would simply mean &quot;store the entities as they were added&quot;). But this would need another column in DB that we&apos;d have to add within oneToMany / manyToMany relationships, but in this case one could save a serialized array holding &quot;entityId =&amp;gt; position&quot; key / value pairs.&lt;/p&gt;

&lt;p&gt;Afterwards, one could easily rebuild / reorder the collection via $collection-&amp;gt;set($entity, $order&lt;span class=&quot;error&quot;&gt;&amp;#91;$entity-&amp;gt;identifier&amp;#93;&lt;/span&gt;);&lt;/p&gt;

&lt;p&gt;If you&apos;ve got another thought about this, please don&apos;t hesitate to point me into the right direction!&lt;/p&gt;</comment>
                    <comment id="13043" author="beberlei" created="Sat, 22 May 2010 02:54:25 +0000"  >&lt;p&gt;this won&apos;t be implemented until 2.1, since its a pretty complex feature. &lt;/p&gt;

&lt;p&gt;Changes are probably required in:&lt;/p&gt;

&lt;p&gt;1. CollectionPersister - Add a new collection persister that takes the position into account&lt;br/&gt;
2. SchemaTool - Add a &apos;col_position&apos; column to either the many-to-many or the one-to-many tables.&lt;br/&gt;
3. EntityPersister - Use and extend current order-by support to make the sorting happen&lt;/p&gt;

&lt;p&gt;You can implement this already though with some performance hit in update scenarios. If you use the ORDER BY support and implement an API around your entity that abstracts those changes and always sets a &quot;position&quot; field on the many entity that is supposed to be sorted.&lt;/p&gt;</comment>
                    <comment id="13044" author="romanb" created="Sat, 22 May 2010 05:35:48 +0000"  >&lt;p&gt;I don&apos;t think we necessarily need a new collection persister. Simply adjusting the ManyToManyPersister to be able to deal with it might be sufficient.&lt;/p&gt;

&lt;p&gt;For OneToMany, that is always persisted from the &quot;many&quot; side, thus there is no collection persister, we would need to adjust the normal persisters.&lt;/p&gt;

&lt;p&gt;They key element for the user should be a new annotation (or corresponding xml/yaml element) @OrderColumn. By default the order should not be persistent, only when an @OrderColumn annotation is present. The name of the order column can have a default, i.e. &quot;position&quot;. Thus this enhancement of persisting the order should be fully backwards compatible.&lt;/p&gt;</comment>
                    <comment id="13045" author="romanb" created="Sat, 22 May 2010 05:41:07 +0000"  >&lt;p&gt;On another note, the getInsertDiff/getDeleteDiff methods of PersistentCollection should already be &quot;ready&quot; for this. That is, when an element in the collection changed only its position, this is already tracked as a change. However the ManyToManyPersister issues no &quot;UPDATE&quot; queries, it simply deletes and inserts. A position change may be more effectively persisted with an UPDATE.&lt;/p&gt;</comment>
                    <comment id="14493" author="beberlei" created="Thu, 30 Sep 2010 03:23:11 +0000"  >&lt;p&gt;From a mailinglist entry, required check/changepoints:&lt;/p&gt;

&lt;p&gt;1. ClassMetadata of Many-To-Many associations have to be extended to publish the required datastructure to the ORM.&lt;br/&gt;
2. All Metadata Mapping Drivers have to be extended&lt;br/&gt;
3. Persisters\ManyToManyCollectionPersister has to be extended to save the key in the many to many table if desired by the user.&lt;br/&gt;
4. Schema-Tool has to be extended to create the additional column.&lt;br/&gt;
5. PersistentCollection has to be extended so that lazy loading of collections with additional key works.&lt;br/&gt;
6. Array- and ObjectHydrator have to be extended to allow fetch join of collections with key column.&lt;br/&gt;
7. Discuss wheather to support this for One-To-Many also with the key-column on the many side. This is much more tricky internally though.&lt;/p&gt;</comment>
                    <comment id="15006" author="beberlei" created="Fri, 24 Dec 2010 04:48:03 +0000"  >&lt;p&gt;Push back to 2.x, we will have support for &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-250&quot; title=&quot;ArrayCollection Key Column @indexBy&quot;&gt;&lt;del&gt;DDC-250&lt;/del&gt;&lt;/a&gt; first and for this at a later release.&lt;/p&gt;</comment>
                    <comment id="17377" author="armetiz" created="Tue, 7 Feb 2012 17:25:33 +0000"  >&lt;p&gt;Hi there,&lt;br/&gt;
I&apos;m looking for this feature.&lt;/p&gt;

&lt;p&gt;Benjamin Eberlei said that : &quot;You can implement this already&quot;, but I don&apos;t understand the &quot;how to&quot;.&lt;/p&gt;

&lt;p&gt;Also,&lt;br/&gt;
The problem should be solve if RDBMS had a &quot;natural&quot; order. An order based on item position inside table.&lt;/p&gt;

&lt;p&gt;To get this feature without any change on Doctrine, I have remplace the PK defined by the target &amp;amp; mapped field identifier. The new PK is a new field with type &quot;integer&quot; and with auto-increment enable.&lt;br/&gt;
In this configuration, Doctrine use the &quot;natural&quot; order of the RDBMS. And I can change order of my item inside Collection and persist it.&lt;/p&gt;

&lt;p&gt;It&apos;s an very bad solution, but It work before an official support.&lt;/p&gt;

&lt;p&gt;Waiting for advices, and solutions,&lt;/p&gt;

&lt;p&gt;Thomas.&lt;/p&gt;</comment>
                    <comment id="17379" author="armetiz" created="Wed, 8 Feb 2012 10:41:00 +0000"  >&lt;p&gt;Answering to Benjamin Eberlei on the &quot;7. Discuss wheather to support this for One-To-Many also with the key-column on the many side. This is much more tricky internally though.&quot;.&lt;/p&gt;

&lt;p&gt;I think that for One-To-Many relations, if user want to store the collection order, Doctrine can store the One-To-Many as Many-To-Many with a &quot;model&quot; limitation. &lt;br/&gt;
In that case, if storing order collection for Many-To-Many work, it should work for One-To-Many.&lt;/p&gt;

&lt;p&gt;What do you think about it ?&lt;/p&gt;</comment>
                    <comment id="17486" author="ndm" created="Wed, 29 Feb 2012 05:41:55 +0000"  >&lt;p&gt;I think that it must be possible to have two keys ordering : the order isn&apos;t obligatory reversible.&lt;/p&gt;

&lt;p&gt;For exemple  with user and group : &lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;You can order groups for one user : with preference by exemple, or importance.&lt;/li&gt;
	&lt;li&gt;And  with a different order,  users for a group : rank by example.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;And maybe more, if you decide to add multi-order : an user show group by his rank in it, if his rank is identical, the order is make by love preference, and after by the importance given by the user (not necessary a number, if we imagine filter on them).&lt;/p&gt;

&lt;p&gt;So a default order can be choice with parametized fields and could be : &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; 
@ManyToMany(targetEntity=&lt;span class=&quot;code-quote&quot;&gt;&quot;Group&quot;&lt;/span&gt;)
...
@JoinFields ( rank: { type: &lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;} , preference:{type:&lt;span class=&quot;code-object&quot;&gt;int&lt;/span&gt;}, importance:{type: string, length: 40} )
@OrderByJoinFields({&lt;span class=&quot;code-quote&quot;&gt;&quot;rank&quot;&lt;/span&gt; = &lt;span class=&quot;code-quote&quot;&gt;&quot;ASC&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;preference&quot;&lt;/span&gt;=&lt;span class=&quot;code-quote&quot;&gt;&quot;ASC&quot;&lt;/span&gt;, &lt;span class=&quot;code-quote&quot;&gt;&quot;importance&quot;&lt;/span&gt;=&lt;span class=&quot;code-quote&quot;&gt;&quot;ASC&quot;&lt;/span&gt; } )
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt; 

&lt;p&gt;In this case the order must be optional and would be clean if another order appears in the same scope (DQL...). And manytomany became virtual entities act as other entities except they don&apos;t appears permetting in the same time a better conception.&lt;/p&gt;

&lt;p&gt;So if the solution take in &lt;a href=&quot;http://www.doctrine-project.org/jira/browse/DDC-181&quot; class=&quot;external-link&quot;&gt;DDC-181&lt;/a&gt; will become the only solution. This would a good idea to document this. Because, this seems to me a very important point.&lt;/p&gt;

&lt;p&gt;My last point is &lt;b&gt;even an unique ordering field&lt;/b&gt; created in the join table will be a &lt;b&gt;big and usefull improvement&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Thank a lot for your beautiful work.&lt;/b&gt;&lt;/p&gt;</comment>
                    <comment id="17487" author="armetiz" created="Wed, 29 Feb 2012 07:05:59 +0000"  >&lt;p&gt;In my point of view, a collection can be order in a single way only.&lt;br/&gt;
If you want to add more than one order between User &amp;amp; Group, it&apos;s a new collection, a new relation.&lt;br/&gt;
Like : &lt;/p&gt;
&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;User.memberOf() : Group[]&lt;/li&gt;
	&lt;li&gt;Group.members() : User[]&lt;/li&gt;
	&lt;li&gt;Group.importantMembers() : User[]&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;And it&apos;s your role to keep a consistency between members &amp;amp; importantMembers array.&lt;/p&gt;

&lt;p&gt;Because ManyToMany join table is the reflection of a state of an ArrayCollection. It&apos;s not a usefull feature to be able to store all of the state of an ArrayCollection, even the order of this Array. It&apos;s just a normal feature that is really missing &lt;img class=&quot;emoticon&quot; src=&quot;http://www.doctrine-project.org/jira/images/icons/emoticons/tongue.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;

&lt;p&gt;Thomas.&lt;/p&gt;</comment>
                    <comment id="17488" author="ndm" created="Wed, 29 Feb 2012 10:14:27 +0000"  >&lt;p&gt;I don&apos;t think:&lt;/p&gt;

&lt;p&gt;If you have three collection, you &lt;b&gt;duplicate one relation 3 times&lt;/b&gt; and it&apos;s easy in consequence &lt;b&gt;to lost the data integrity and unicity&lt;/b&gt;.&lt;/p&gt;

&lt;p&gt;By example :&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;Thomas have rank 10 in Admin&lt;/li&gt;
	&lt;li&gt;Thomas think the admin group has importance noted 3 on all of his groups.&lt;/li&gt;
	&lt;li&gt;If a responsable of admin group decide to delete Thomas from it.&lt;/li&gt;
	&lt;li&gt;Thomas, in his ordered list of groups, think always to be in group admin.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;So in my idea, the &lt;b&gt;many to many relation&lt;/b&gt; isn&apos;t just an array collection, but &lt;b&gt;should be an virtual entity&lt;/b&gt;. In UML or in Merise method this is a common problem to have a parametized relation. I think an orm should just implement this.&lt;/p&gt;
</comment>
                    <comment id="17489" author="armetiz" created="Wed, 29 Feb 2012 10:43:59 +0000"  >&lt;p&gt;Hum,&lt;br/&gt;
I agree with you.. In a SQL Schema, it&apos;s a good choice to add many fields in a ManyToMany join table to description &quot;order&quot;.&lt;/p&gt;</comment>
                    <comment id="17535" author="armetiz" created="Wed, 7 Mar 2012 15:12:35 +0000"  >&lt;p&gt;I just want to add a piece of Doctrine ORM Document : &lt;/p&gt;

&lt;p&gt;&quot;When working with collections, keep in mind that a Collection is essentially an &lt;b&gt;ordered map&lt;/b&gt; (just like a PHP array). That is why the remove operation accepts an index/key. removeElement is a separate method that has O ( n) complexity using array_search, where n is the size of the map.&quot;&lt;/p&gt;</comment>
                    <comment id="17636" author="armetiz" created="Fri, 23 Mar 2012 09:45:13 +0000"  >&lt;p&gt;Hi there,&lt;br/&gt;
After several discussions. on IRC, I have changed my point of view.&lt;/p&gt;

&lt;p&gt;Doctrine Documentation says : &quot;When working with collections, keep in mind that a Collection is essentially an ordered map (just like a PHP array)&quot;.&lt;br/&gt;
So, I think that Doctrine have to be able to store or not the order of a Collection. By adding a new field on the Joined table to store the position of each elements.&lt;/p&gt;

&lt;p&gt;But I not agree with @Nicolas. Because in his case, he&apos;s talking about Association Class : &lt;a href=&quot;http://etutorials.org/Programming/UML/Chapter+6.+Class+Diagrams+Advanced+Concepts/Association+Class/&quot; class=&quot;external-link&quot;&gt;http://etutorials.org/Programming/UML/Chapter+6.+Class+Diagrams+Advanced+Concepts/Association+Class/&lt;/a&gt;&lt;br/&gt;
Because he&apos;s talking of a business logic, he&apos;s talking of a dedicated Entity class.&lt;/p&gt;

&lt;p&gt;What do you think about it ?&lt;/p&gt;

&lt;p&gt;Thomas;&lt;/p&gt;
</comment>
                    <comment id="18593" author="armetiz" created="Fri, 31 Aug 2012 13:43:00 +0000"  >&lt;p&gt;Any news ? &lt;/p&gt;</comment>
                    <comment id="18841" author="mnapoli" created="Tue, 16 Oct 2012 07:43:02 +0000"  >&lt;p&gt;Hi, any news on this?&lt;/p&gt;

&lt;p&gt;If I may add any info to this feature request, maybe something like JPA/Hibernate could be a good start?&lt;/p&gt;

&lt;p&gt;See &lt;a href=&quot;http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html&quot; class=&quot;external-link&quot;&gt;http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html&lt;/a&gt; or &lt;a href=&quot;http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-indexed&quot; class=&quot;external-link&quot;&gt;http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-indexed&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea in Hibernate is that you persist the order of the list in an extra column. This column is not a field of the entity however.&lt;/p&gt;</comment>
                </comments>
                <issuelinks>
                        <issuelinktype id="10000">
                <name>Duplicate</name>
                                                <inwardlinks description="is duplicated by">
                            <issuelink>
            <issuekey id="10523">DDC-181</issuekey>
        </issuelink>
                    </inwardlinks>
                            </issuelinktype>
                        <issuelinktype id="10001">
                <name>Reference</name>
                                                <inwardlinks description="is referenced by">
                            <issuelink>
            <issuekey id="10718">DDC-250</issuekey>
        </issuelink>
                    </inwardlinks>
                            </issuelinktype>
                    </issuelinks>
                <attachments>
                </attachments>
            <subtasks>
        </subtasks>
        </item>
</channel>
</rss>