this is standard relation() stuff thats documented in the ORM tutorial  
in "Querying with Joins".


On Aug 3, 2009, at 4:59 PM, thatsanicehatyouh...@mac.com wrote:

>
> Hi,
>
> I'm circling around an answer for a problem but am not quite getting
> it. I have two tables: Plugging and Cartridge. Plugging has a to-one
> relation to Cartridge, and the inverse relation is to-many. Cartridge
> has a field called "number" and plugging has a field called "active".
> I want to build a query to retrieve a single plugging, and this works
> for me:
>
> plugging, cart = session.query(Plugging,
> Cartridge).filter(Cartridge.number ==
> cartNo).filter(Plugging.cartridge_pk ==
> Cartridge.pk).filter(Plugging.active == True).one()
>
> This seems overly complicated - I shouldn't need to specify the
> primary keys (pk) since the foreign keys are already defined (I'm
> using autoload with postgresql). My first attempt at a query was this:
>
> plugging = session.query(Plugging).filter(Plugging.cartridge.number ==
> cartNo).one()
>
> ...but that turned out to be too optimistic (ignore for the moment
> that I left out the "active" filter). What is the best practice for
> simplifying the first query?
>
> Cheers,
> Demitri
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to