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