On Thu, Jul 24, 2008 at 09:56:01AM +0200, dimi duj wrote: > I'm new to SQLObject so my question would be probably stupid... ;)
Welcome! Don't be too afraid. (-: > I'm trying to do a foreign key to the same table but I've got an error > > Here's an example: > > class NestedTest(SQLObject): > attr1 = StringCol() > attr2 = StringCol() > parent = ForeignKey('NestedTest') > #NestedTest.createTable() > NestedTest.sqlmeta.addJoin(MultipleJoin('NestedTest',joinMethodName='childs')) > > n1=NestedTest(attr1='first', attr2='55408',parent=None) > n2=NestedTest(attr1='second', attr2='55409', parent=n1) > n3=NestedTest(attr1='third', attr2='55410', parent=n1) > > print n2.childs [skip] > raise OperationalError(ErrorMessage(e)) > sqlobject.dberrors.OperationalError: Unknown column 'nested_test_id' in > 'where clause' > Exception exceptions.AttributeError: "'NoneType' object has no attribute > 'print_exc'" in <function _removeReceiver at 0x12214f0> ignored MultipleJoin expects an "*_id" column in the other table (even if the other table is the same table itself). ForeignKey provides such key but you have to tip MultipleJoin what column to use. This works for me: class NestedTest(SQLObject): attr1 = StringCol() attr2 = StringCol() parent = ForeignKey('NestedTest', default=None) children = MultipleJoin('NestedTest', joinColumn='parent_id') NestedTest.createTable() n1=NestedTest(attr1='first', attr2='55408') n2=NestedTest(attr1='second', attr2='55409', parent=n1) n3=NestedTest(attr1='third', attr2='55410', parent=n1) print n1.children The output is: [<NestedTest 2 attr1='second' attr2='55409' parentID=1>, <NestedTest 3 attr1='third' attr2='55410' parentID=1>] Seems ok for me. PS. Proper plural for for the word 'child' is 'children' :-) Oleg. -- Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ sqlobject-discuss mailing list sqlobject-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss