So what about one table only?
(main idea taken from http://wiki.sqlobject.org/joinexample.html)
sqlhub.processConnection = connectionForURI('sqlite:/:memory:')
blockA = Blocks(name="blockA",)
blockB = Blocks(name="blockB", parent=blockA)
blockC = Blocks(name="blockC", parent=blockB)
for row in Blocks.select():
print "ROW:", row
print "PARENT:", row.parent
print "CHILD:", row.child
PS: please try to "reply to all" so others in the SQLobject discussion group can profit as well
For example:The schema:BlockA --------> BlockB -------> BlockCWe have 3 blocks and 2 connections. For this case the data in the table should be:Block table:id | name-----------1 | "BlockA"2 | "BlockB"3 | "BlockC"Connection table:id | src | dst---------------1 | 1 | 2 # BlockA -> BlockB connection2 | 2 | 3 # BlockB -> BlockC connection...3 | 1 | 1 # this is connection from BlockA to itself, but this is OK (not shown on the schema above)4 | 3 | 4 # wrong entry... it should not be possible to enter something like this in a database, block with id 4 is non-existant!Now, how should I declare classes for Block and Connection table?Each entry in a connection table should have id andsrc, which should be a reference to an existing block, anddst, which should be again a reference to an existing blockThank you for your answer.Zoran
To: Zoran Bošnjak
Subject: Re: FW: [SQLObject] table ralationsZoran,
I do not really understand, what you are trying to do. Can you send me a short example of data for both tables?
On Thu, Jan 8, 2009 at 8:36 AM, Zoran Bošnjak <Zoran.Bosnjak@sloveniacontrol.si> wrote:
Petr,do you understand my question. Can you help me solve it?regards,Zoran
From: Zoran Bošnjak
Sent: Wednesday, January 07, 2009 10:17 AM
Subject: RE: [SQLObject] table ralationsSorry for the confusion...I don't want to have a "Connection" in a database unless the connection is between existing "Blocks".Please correct my class definition for Block and Connection so, that it won't be even possible to create such connection.Zoran
From: firstname.lastname@example.org [mailto:email@example.com] On Behalf Of Petr Jakeš
Sent: Wednesday, January 07, 2009 9:51 AM
To: Zoran Bošnjak
Subject: Re: [SQLObject] table ralations# create dumb connection
# it should not work, because there is no blocks!!!
Why do you think this should not work? AFIK above mentioned just insert one row (record) in your table Connection. Exactly as the SQL below describes.
INSERT INTO "connection" VALUES(1,150,250); COMMIT;