Hi everyone

I have just learned that using select() -- rather than
selectBy() -- on a foreign key can generate very weird
results. I already know about the work-around
described by Oleg here

http://pythonpaste.org/archives/message/20070131.133611.ae4d5c7e.pt-BR.html

That works wonders. However, would you consider making
..select() refuse to work on foreign keys? Or give the
right result? 


An example (I meant to put this on the wiki, but
couldn't find out how! If someone could upload it onto
a page 'Using .select() with foreign keys' that might
be useful for others.):

class X(SQLObject):
    
    pass

class Y(SQLObject):

    key = ForeignKey('X')
    pass

X.createTable()
Y.createTable()

x1=X()
x2=X()
x3=X()

y1=Y(key=x1)
y2=Y(key=x2)

In this example, all the values returned by .select()
are wrong:

>>> Y.select(Y.q.key==x1).count()
4L
>>> Y.select(Y.q.key==x3).count()
2L
>>> Y.select(Y.q.key!=x1).count()
2L
>>> Y.select(Y.q.key!=x3).count()
4L


Using, eg, Y.select(Y.q.keyID == x1.id) produces the
correct result. Perhaps .select() could either produce
the correct result or fail with an exception if called
on a foreign key?

I would be happy to upload this to the wiki, but
embarassingly I couldn't find out how to add a page...
: /

Best

Juerg



      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to