On Jan 8, 2013, at 11:46 PM, Alexey Vihorev wrote:

> Hi all!
>  
> Apparently, a relation declared using sqlalchemy.ext.orderinglist does not 
> track sorting:


you need to call the reorder() method:

http://docs.sqlalchemy.org/en/rel_0_8/orm/extensions/orderinglist.html?highlight=reorder#sqlalchemy.ext.orderinglist.OrderingList.reorder



>  
> 1.  class Parent(Base):
> 
>          …
> 
> 2.      name = Column(Text)
> 
> 3.      children = relationship('Child', backref='parent',
> 
> 4.          collection_class=ordering_list('position', 1),
> 
> 5.          order_by='Child.position'
> 
> 6.      )
> 
>  
> p = Parent(name='Thomas')
> 
> session.add(p)
> 
> lst = p.children
> 
> lst.append(Child(name="Mary"))
> 
> lst.append(Child(name="John"))
> 
> lst.append(Child(name="Kenny"))
> 
> session.commit()
> 
>  
> 
> p = session.query(Parent).get(1)
> 
> print(p.children) #prints [<Mary, position:1>, <John, position:2>, <Kenny, 
> position:3>]
> 
>  
> 
> p.children.sort(key=attrgetter('name'))
> 
> print(p.children) #prints [<John, position:2>, <Kenny, position:3>, <Mary, 
> position:1>]
> 
>  
> 
> session.commit() does not help the matters either. So, how do I initiate 
> re-numeration manually (except for iterating records and assigning them 
> numbers)?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to