public
Last active

SQLObject foreign_keyID vs. foreign_key_ID

  • Download Gist
sqlobject_foreignkey_id.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/bin/env python
"""Demonstrate use of underscore in foreign key "q" attribute with Outer."""
 
from sqlobject import *
from sqlobject.sqlbuilder import *
 
class Foo(SQLObject):
 
bars = MultipleJoin('Bar')
 
class Bar(SQLObject):
 
foo = ForeignKey('Foo')
 
uri = 'sqlite:/:memory:'
sqlhub.processConnection = connectionForURI(uri, debug=False)
Foo.createTable()
Bar.createTable()
 
foo = Foo()
Bar(foo=foo)
Bar(foo=foo)
Bar(foo=foo)
 
# must use fooID here
select_results = Bar.select(join=LEFTJOINOn(None, Foo, Bar.q.fooID == Foo.q.id))
print 'LEFTJOINOn fooID:'
for select_result in select_results:
print select_result
 
# must use foo_ID here
expr = EXISTS(Select(Foo.q.id, where=Outer(Bar).q.foo_ID == Foo.q.id))
select_results = Bar.select(expr)
print 'Select foo_ID:'
for select_result in select_results:
print select_result
 
# fooID fails here
expr = EXISTS(Select(Foo.q.id, where=Outer(Bar).q.fooID == Foo.q.id))
select_results = Bar.select(expr)
print 'Select fooID:'
for select_result in select_results:
print select_result

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.