Hello! Sorry for late answer. I am very busy these days - with my
family, job, construction of our dacha...

On Fri, Jun 14, 2013 at 04:57:10PM -0400, Rhubarb Sin <rhubarb...@gmail.com> 
wrote:
> I was surprised when I recently discovered I had to add an extra
> underscore to use a SQLObject class's foreign key ID when using
> sqlobject.sqlbuilder.Outer. For example, this works:
> 
> EXISTS(Select(Foo.q.id, where=Outer(Bar).q.foo_ID == Foo.q.id))
> 
> This does not work:
> 
> EXISTS(Select(Foo.q.id, where=AND(Outer(Bar).q.fooID == Foo.q.id)))

   What is going on is this: Outer works only symbolically - it
generates column names without looking into class definition. That is,
Outer(Bar).q.foo_ID puts "bar.foo_ID" into an SQL query and
Outer(Bar).q.fooID generates "bar.fooID" without testing if such columns
exist. There is no column fooID in table bar, hence the second query
produces an error. There is a column foo_id, and bar.foo_ID works
because SQL is case-insensitive language.

   If you read sqlbuilder.py you can find that Outer implemented using
Table and Field helper classes. I can replace them with SQLObjectField
and SQLObjectTable:

class SQLObjectOuterField(SQLObjectField):
    def tablesUsedImmediate(self):
        return []

class SQLObjectOuterTable(SQLObjectTable):
    FieldClass = SQLObjectOuterField

class SQLObjectOuter:
    def __init__(self, table):
        self.q = SQLObjectOuterTable(table)

   Now SQLObjectOuter(Bar).q.foo_ID doesn't work but
SQLObjectOuter(Bar).q.fooID works exactly as you expected, as well as
SQLObjectOuter(Bar).q.foo.

   I think I can change the implementation of Outer in sqlbuilder using
SQLObjectTable/Field helper but that requires a lot of testing. I doubt
I will have time for it in June.

Oleg.
-- 
     Oleg Broytman            http://phdru.name/            p...@phdru.name
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to