Hi!

On Wed, Feb 16, 2011 at 02:20:33PM +0800, Jason Heeris wrote:
> I'm trying to filter a selection from one table by looking up a
> referenced value in another table. An example is probably the easiest
> explanation:
> 
> ----
> class DocumentType (SQLObject) :
>     """ What type the document is assigned to.
>     """
>     dbType = StringCol()
> 
> class Document (SQLObject) :
>     """ Location of stored documents
>     """
>     dbPath = StringCol()
>     dbDocumentType = ForeignKey('DocumentType')
> 
> def DocumentSearch(text, type=None):
> 
>     # initial query with text
>     docs = dbase.dbase.SVNDocument.select(...)
> 
>     if type:
>         docs.filter(...)
> 
>     return list(docs)
> ----
> 
> The "docs.filter(...): is where I want to allow only those Documents
> whose dbDocumentType refers to the DocumentType with dbType == type. I
> know this must be simple, but it's been a while since I used SQLObject
> and I just can't see it.

   If SVNDocument is actually Document in this example, and type to
filter must be compared equal to DocumentType.dbType, then filter
should be something like this:

    docs.filter(
        (Document.q.dbDocumentTypeID==DocumentType.q.id) &
        (DocumentType.q.dbType==type)
    )

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

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to