On Dec 11, 2008, at 5:50 AM, Andreas Jung wrote:

>
> This works to some degree:
>
> class Hierarchies(Base):
>     __tablename__ = 'hierarchies'
>     __table_args__ = (
>         { 'autoload' : True, })
>
>     parent_id = Column('parent_id', Integer,  
> ForeignKey('hierarchies.id'))
>
>     _children = relation('Hierarchies',
>
> primaryjoin='Hierarchies.parent_id==Hierarchies.id',
>                          order_by=['Hierarchies.pos'],
>                          cascade="all",
>                          backref=backref("parent",
> remote_side=['Hierarchies.id'])
>
>
> hso = session.query(Hierarchies).filter_by(id=1641).one()
> print hso._children
> for c in hso._children:
>         print c
>
> hso._children is a PropertyLoader instance in this case that can not  
> be used
> for iteration.
>
> The "same" code implemented as standard mapper using SA 0.3 behaves as
> it should.
> I can not see the difference how to make it work with SA 0.5.

Actually that code doesn't work for me at all so I dont know how  
you're getting that result.   When I changed it to be "correct", I  
uncovered a bug relating to using a string for remote_side in  
backref() and fixed in r5460.

the strings you give to the arguments are eval'ed, so any list  
constructs need to be part of the string too (but are not needed  
here).    So here are the ways you can do this, the first one is the  
only one that relies upon the fix in 5460:

class Hierarchies(Base):
     __tablename__ = 'hierarchies'
     __table_args__ = ({ 'autoload' : True, })

     parent_id = Column('parent_id', Integer,  
ForeignKey('hierarchies.id'))

     _children =  
relation 
('Hierarchies',primaryjoin='Hierarchies.parent_id==Hierarchies.id',
                          order_by='Hierarchies.pos',
                          cascade="all",
                          backref=backref("parent",  
remote_side='Hierarchies.id')
                          )


class Hierarchies(Base):
     __table__ = Table('hierarchies', Base.metadata, autoload=True)

     _children =  
relation 
('Hierarchies',primaryjoin=__table__.c.parent_id==__table__.c.id,
                          order_by=__table__.c.pos
                          cascade="all",
                          backref=backref("parent",  
remote_side=__table__.c.id)
                          )

# not using autoload, this is the core "declarative" usage  
since...well its declarative:

class Hierarchies(Base):
     __tablename__ = 'hierarchies'

     id = Column(Integer, primary_key=True)
     parent_id = Column(Integer, ForeignKey('hierarchies.id'))
     pos = Column(Integer)

     _children = relation('Hierarchies',primaryjoin=parent_id==id,
                          order_by=pos
                          cascade="all",
                          backref=backref("parent", remote_side=id)
                          )



--~--~---------~--~----~------------~-------~--~----~
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