hi,
i'm trying to muddle my way through properties.py
in an attempt to understand what backref does, but
i'm getting a bit confused.
ultimately i'm just trying to clarify in my mind
what the differences are between using backref
and defining two separate properties. this is
illustrated in the sample code before, by
toggling the USE_BACKREF flag. when True,
the assert at the end succeeds, while when
False, the assert fails (this was surprising
to me, which probably just shows my confusion).
any insights into how things work would be
appreciated.
thanks,
d
ps. mike, did you have any further thoughts
on the information_schema?
---
import sqlalchemy as rdb
USE_BACKREF = True
# Setup data
engine = rdb.create_engine('sqlite://', echo=True)
t1 = rdb.Table(
't1', engine,
rdb.Column('id', rdb.Integer, primary_key=True),
)
t1.create()
class C1(object):
pass
m1 = rdb.mapper(C1, t1)
t2 = rdb.Table(
't2', engine,
rdb.Column('id', rdb.Integer, primary_key=True),
rdb.Column('t1id', rdb.Integer, rdb.ForeignKey(t1.c.id)),
)
t2.create()
class C2(object):
pass
m2 = rdb.mapper(C2, t2)
# Choice of backref here
if USE_BACKREF:
m2.add_property(
't1', rdb.relation(m1, backref='t2s')
)
else:
m2.add_property(
't1', rdb.relation(m1)
)
m1.add_property(
't2s', rdb.relation(m2)
)
# Test
a = C1()
a.id = 0
for i in xrange(10):
b = C2()
b.id = i
b.t1 = a
rdb.objectstore.commit()
assert len(a.t2s) == 10
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users