yes, it was a bug that declarative wasn't translating the backref()  
arguments from strings.

On Jan 12, 2009, at 10:22 AM, MikeCo wrote:

>
> Must have been a bug in the default constructor prior to 0.5.0 final.
> I got the same error rerunning with earlier version. Strange, I don't
> remember now how I had this running before. Maybe with my own
> constructor, but not worth igging to find out, it works with final
> release.
>
> On Jan 11, 1:43 pm, Darren Govoni <dar...@ontrenet.com> wrote:
>> Ahhh, looks like I'm on rc4. Let me try final and see.
>>
>> On Sun, 2009-01-11 at 13:10 -0500, Michael Bayer wrote:
>>> 0.5.0 final ?
>>
>>> On Jan 11, 2009, at 12:21 PM, Darren Govoni wrote:
>>
>>>> Hi MikeCo,
>>>>  I tried your example, and got this error from SA 0.5.
>>
>>>> ValueError: need more than 0 values to unpack
>>
>>>> Darren
>>
>>>> On Fri, 2009-01-09 at 20:33 -0800, MikeCo wrote:
>>>>> from sqlalchemy import *
>>>>> from sqlalchemy.orm import *
>>>>> from sqlalchemy.ext.declarative import declarative_base
>>
>>>>> dbname = ''
>>>>> dburl = 'sqlite:///%s' % dbname
>>
>>>>> # set up environment
>>>>> eng = create_engine(dburl, echo=False)
>>>>> meta = MetaData(bind=eng)
>>>>> Base = declarative_base(metadata=meta)
>>>>> Session = sessionmaker()
>>
>>>>> # D  self referential
>>>>> class D(Base):
>>>>>    __tablename__ = 'D'
>>>>>    id = Column(Integer, primary_key=True)
>>>>>    id_d = Column(Integer, ForeignKey('D.id'))
>>>>>    name = Column(Text)
>>>>>    child = relation('D',
>>>>>        backref=backref('parent', remote_side='D.id'))
>>>>>    def __repr__(self):
>>>>>        return '--<D> (id:%s->id_d:%s) %s --' % (self.id,  
>>>>> self.id_d,
>>>>> self.name)
>>
>>>>> def initdb():
>>>>>    print '# create the database'
>>>>>    meta.drop_all(checkfirst=True)
>>>>>    meta.create_all()
>>>>>    sess = Session()
>>
>>>>>    # insert some data for self-reference relationship
>>>>>    for ddata in ('d-one', 'd-two'):
>>>>>        dobj = D(name=ddata)
>>>>>        sess.add(dobj)
>>>>>        dobj2 = D(name=ddata+'-child1')
>>>>>        dobj.child.append(dobj2)
>>>>>        dobj2 = D(name=ddata+'-child2')
>>>>>        dobj.child.append(dobj2)
>>>>>        dobj3 = D(name=ddata+'-child2'+'-child3')
>>>>>        dobj2.child.append(dobj3)
>>>>>    sess.commit()
>>>>>    sess.close()
>>
>>>>> def printobj(obj, indent=''):
>>>>>    # recursive list
>>>>>    print '%s%s' % (indent, obj)
>>>>>    if hasattr(obj, 'child'):
>>>>>        for ch in obj.child:
>>>>>            printobj(ch, indent=indent+'    ')
>>
>>>>> def listd():
>>>>>    # retrieve and list
>>>>>    sess = Session()
>>>>>    print '# D->D'
>>>>>    query = sess.query(D).filter(D.id_d==None).order_by(D.name)
>>>>>    for dobj in query:
>>>>>        printobj(dobj)
>>>>>    sess.close()
>>
>>>>> def tst3():
>>>>>    # do stuff with self referential class D
>>>>>    sess = Session()
>>>>>    print "#switch parentage of name 'd-two-child1' to 'd-one'"
>>>>>    print '# before'
>>>>>    listd()
>>>>>    child = sess.query(D).filter(D.name=='d-two-child1').one()
>>>>>    parent = sess.query(D).filter(D.name=='d-one').one()
>>>>>    eng.echo=True
>>>>>    child.parent = parent
>>>>>    child.name += ' MOVED'
>>>>>    sess.commit()
>>>>>    eng.echo=False
>>>>>    print '# after'
>>>>>    listd()
>>
>>>>> initdb()
>>>>> tst3()
> >


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

Reply via email to