Last active
December 18, 2015 12:48
-
-
Save RhubarbSin/5785040 to your computer and use it in GitHub Desktop.
SQLObject foreign_keyID vs. foreign_key_ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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