Skip to content

Instantly share code, notes, and snippets.

@RhubarbSin
Last active December 18, 2015 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RhubarbSin/5785040 to your computer and use it in GitHub Desktop.
Save RhubarbSin/5785040 to your computer and use it in GitHub Desktop.
SQLObject foreign_keyID vs. foreign_key_ID
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment