On Jan 20, 2006, at 4:17 PM, [EMAIL PROTECTED] wrote:
as a test i looked into trying to create
a 2-loop in the code below, but failed
because FKs require the referent to already
exist. the followup question to this is:
do you imagine ever allowing the creation
of such relations via sqlalchemy?
within the SQL package alone, you can set up these relations like this:
t1 = Table('t1', testbase.db,
Column('c1', Integer, primary_key=True),
Column('c2', Integer, ForeignKey('t2.c1'))
)
t2 = Table('t2', testbase.db,
Column('c1', Integer, primary_key=True),
Column('c2', Integer)
)
t2.create()
t1.create()
t2.c.c2.append_item(ForeignKey('t1.c1'))
I would need to add a "create()" method to the ForeignKey object
itself to enable it to happen in the DB.
i was still curious as to what would happen
if i manually created the table definitions
and commented out the .create()s - in that
case i got a:
".../mapping/topological.py", line 96, in sort
raise "Circular dependency detected " + repr(edges) + repr(queue)
Circular dependency detected {Mapper|C2|t2 (idself=1077381996):
{Mapper|C1|t1 (idself=1077381964): True}, Mapper|C1|t1
(idself=1077381964): {Mapper|C2|t2 (idself=1077381996): True}}[]
which makes sense, since the cycle won't get
caught by the 't[0] is t[1]' check.
nevertheless, i also wonder if this is something
that you expect to support in the future?
I have been refactoring the cyclical dependency code in the
topological.py and objectstore.py methods to support cyclical
relationships that span more than one table. Since it is clear to me
that such a relationship, if you had to write hand-coded SQL and
shove it into an objectstore.commit() is a lot of effort, and its
exactly the sort of thing a topological sort should be able to do.
So far I have a 2-table version like the one above working without
any extra curve balls thrown at it yet; in SVN its in the branch "/
sqlalchemy/branches/cyclical" and theres a new unit test package
"cycles.py".
What this is doing is taking the usual dependency sort at the table
level, detecting if there are cycles, and if so breaking it down to a
dependency sort at the object instance level. So you still need to
ultimately not have a circular relationship between two individual
rows; i havent figured out how that situation should be handled yet.
do you see your tables having such cycles within them, i.e. two rows
pointing to each other ?
- mike
-------------------------------------------------------
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