Skip to content

@RhubarbSin /sqlobject_foreignkey_id.py
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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
Something went wrong with that request. Please try again.