I have two tables:

class handset_brand(SQLObject):
        brand = StringCol(alternateID = True, length = 50)
        handsets = SQLMultipleJoin('handset')

class handset(SQLObject):
        handset_brand = ForeignKey('handset_brand')
        model = StringCol(alternateID = True, length = 25)


I want to query the handsets of one brand. This should be obvious, right?
Well, at least for me it isn't, it does not work as expected.

Try 1
-----
I use the name as defined in the class, most obvious choice:

print handset.select(handset_brand==4)
SELECT handset.id_handset, handset.id_handset_brand, handset.model FROM handset WHERE 0

It translates handset_brand==4 as 0!!!

Try 2
-----
Second guess is using the foreign field syntax:

print handset.select(handset_brandID==4)
NameError: name 'handset_brandID' is not defined

It does not even recognise it.

Try 3
-----
Well, what if I use the dotq syntax?

print handset.select(handset.q.handset_brandID==4)
SELECT handset.id_handset, handset.id_handset_brand, handset.model FROM handset WHERE (handset.id_handset_brand = 4)

This one works!

Conclusion: it is not obvious!

What am I doing wrong? What is the recommended way? Shouldn't it work as in "Try 1"?


--

Pau


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to