Does session management only work with explicit relation and backref 
declarations on a mapper?

Given the declarations at the bottom of this note, I've tried this:

s = get_session() # returns session
p = picker(name=bkc)
s.save(p)
s.flush()
o = order(ordernumber='xyz')
s.save(o)
s.flush()

p.orders  # returns []
p.orders.append(o)
s.flush()
p.orders # returns [order(xyz)] 

p.orders.remove(o)
s.flush()

p.orders # returns []
o.picker = p.id
s.flush() # does proper sql update to set picker id on order table ok

p.orders # returns [] but I expect it to return  the order

I'm going to use backref to work around this, I bet that will resolve the
problem, but I'm curious why the mapper doesn't discover foreignkeys 
itself and watch for direct manipulation.. 

---------

metadata = MetaData(name='meta')

Tpicker = Table('pickers', metadata,
                Column('id', Integer, Sequence('pid'), primary_key=True, 
nullable = False),
                Column('name', String(32), nullable=False, unique=True),
            )

Torder = Table('orders', metadata,
               Column('id', Integer, Sequence('oid'), primary_key=True, 
nullable = False),
               Column('ordernumber', String(8), nullable=False, unique=True),
               Column('priority', Integer),
               Column('picker', Integer, ForeignKey(Tpicker.c.id)),
       )

class auto_attr(object):
    def __init__(self, **kw):
        for k, v in kw.items():
            setattr(self, k, v)

class picker(auto_attr):
    pass


class order(auto_attr):
    pass

mapper(picker, Tpicker, properties={
       'orders': relation(order),
    })

mapper(order, Torder)




-- 
Brad Clements,                [EMAIL PROTECTED]    (315)268-1000
http://www.murkworks.com                          
AOL-IM or SKYPE: BKClements



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to