Re: Couple of questions...

John Lenton <[email protected]> Tue, 20 Apr 2004 15:57:20 -0300
Newsgroups gmane.comp.python.modeling
Message-ID <[email protected]>
Sender: John Lenton <[email protected]>

On Tue, Apr 20, 2004 at 09:46:39AM -0700, Aaron Freeman wrote:
> (1) Is there a debug flag somewhere that dump all SQL queries to the
> console?
> 
> (2) How are nested joins accomplished?
> 
> For example, in the AuthorBooks schema, lets assume there is another table
> called publisher that has a 1-M relationship with books, like so (sorry
> about the formatting):
> 
> ............................................................................
> .............
> .+-----------+.(0,1)..............(0,*).+-------+.(0,*)..............(0,1).+
> .|..Writer...|<-author----------books->>|.Book..|<<-books-------publisher->|
> .Publisher.|.
> .|-----------|.(nullify)......(cascade).|-------|..........................|
> .|.lastName..|..........................|.title.|..........................|
> .bizName...|.
> .|.firstName.|..........................|.price.|..........................|
> .location..|.
> .|.age.......|.(0,1)....................+-------+..........................+
> .|.birthday..|<-pygmalion--+................................................
> .............
> .+-----------+.(nullify)...|................................................
> .............
>  
> .....|....................|.................................................
> ............
> ......+--------------------+................................................
> .............
> ............................................................................
> .............
> 
> How would I get writers by publisher?
>
> More specifically, is there an elegant way to do a nested join in a single
> query, or do I just have to do a single writer-book join and then iterate
> over the resultset for the second join?

I don't think so. I'd do it with

   [ i.valueForKeyPath('books.author') for i in ec.fetch('Publisher') ]

which is clean enough for me. I guess what you'd want is for
valueForKeyPath to be callable on a class... :)

-- 
John Lenton ([email protected]) -- Random fortune:
Sobre toda cosa guardada guarda tu corazón, porque de él emana la vida.
		-- Salomón. 


-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click