Re: [SQLObject] Filtering selections via foreign keys
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Oleg B. <ph...@ph...> - 2011-02-16 09:05:30
|
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/ ph...@ph...
Programmers don't die, they just GOSUB without RETURN.
|