[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Kirk Strauser
On Friday 31 July 2009 10:19:29 am Michael Bayer wrote: > BillingInfo.__table__. BillingInfo is a python class, billing_table is > the Table object. After all that, it turned out that yet *another* table needed to be linked in. Here's what I finally ended up with: class Invoice(Base): Bi

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Michael Bayer
Kirk Strauser wrote: > > On Friday 31 July 2009 09:16:21 am Michael Bayer wrote: > >> you likely want to call correlate(billing_table) on your select. rows >> inside the subquery want to correlate outwards to the parent billing >> table. > > Resulting in: > > sqlalchemy.exc.InvalidRequestError:

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Kirk Strauser
On Friday 31 July 2009 09:16:21 am Michael Bayer wrote: > you likely want to call correlate(billing_table) on your select. rows > inside the subquery want to correlate outwards to the parent billing > table. Resulting in: sqlalchemy.exc.InvalidRequestError: Mapper 'Mapper|BillingInfo|bllginfo

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Michael Bayer
Kirk Strauser wrote: > > On Friday 31 July 2009 08:30:52 am Kirk Strauser wrote: >> On Thursday 30 July 2009 04:26:20 pm Michael Bayer wrote: >> > you have to get the select() syntax right: >> > >> > >> > BillingInfo = relation('BillingInfo', >> > >> > primaryjoin="and_(Invoice.pay2addrid==Billing

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Kirk Strauser
On Friday 31 July 2009 08:30:52 am Kirk Strauser wrote: > On Thursday 30 July 2009 04:26:20 pm Michael Bayer wrote: > > you have to get the select() syntax right: > > > > > > BillingInfo = relation('BillingInfo', > > > > primaryjoin="and_(Invoice.pay2addrid==BillingInfo.pay2addrid,Invoice.cust > >

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-31 Thread Kirk Strauser
On Thursday 30 July 2009 04:26:20 pm Michael Bayer wrote: > you have to get the select() syntax right: > > > BillingInfo = relation('BillingInfo', > > primaryjoin="and_(Invoice.pay2addrid==BillingInfo.pay2addrid,Invoice.custom >er== > select([Customer.customer]).where(Cu

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-30 Thread Michael Bayer
you have to get the select() syntax right: BillingInfo = relation('BillingInfo', primaryjoin="and_(Invoice.pay2addrid==BillingInfo.pay2addrid,Invoice.customer== select([Customer.customer]).where(Customer.xrscustid==BillingInfo.xrscustid))") Kirk Strauser wrote: >

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-30 Thread Kirk Strauser
On Thursday 30 July 2009 01:31:21 pm Michael Bayer wrote: > oh, its the string. OK so dont do ForeignKeyConstraint, but definitely > add to the Invoice.BillingInfo relation() all the information needed > within the primaryjoin to select the correct row. seems like it would be > (pseudocode) "i

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-30 Thread Michael Bayer
Kirk Strauser wrote: > > > > But Invoice doesn't have both of those columns. It has a String reference > to > Customer, while BillingInfo has an Integer reference to Customer [1]. > That's > why I ended up with the cyclic relation, and wouldn't otherwise need to > involve Customer at all. oh, it

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-30 Thread Kirk Strauser
On Thursday 30 July 2009 12:56:19 pm Michael Bayer wrote: > at this point, invoices[0] is the invoice that is subject to the given > filter criterion. With you so far. > > print invoices[0].BillingInfo.typeship > now this part is very unusual and is something I haven't tested. Your > foreign

[sqlalchemy] Re: Fetching wrong values from a query involving composite primary keys

2009-07-30 Thread Michael Bayer
Kirk Strauser wrote: > > invoices = session.query(Invoice) > invoices = invoices.join(BillingInfo) > invoices = invoices.join((Customer, > BillingInfo.xrscustid==Customer.xrscustid)) > > invoices = invoices.filter(BillingInfo.typeship=='GBL') > invoices = invoices.filter(Invoice.invid==2663703) a