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)

at this point, invoices[0] is the invoice that is subject to the given
filter criterion.

>
> print invoices[0].BillingInfo.typeship

now this part is very unusual and is something I haven't tested.  Your
foreign key is to only one column of a composite primary key - very
strange.   So SQLA probably sees this as "many-to-one" but the result in
which the lazy load will incur is essentially random since many
BillingInfo entries may have that same value.

Its very likely that your linkage here is incorrect, and you in fact want
to declare, at least within SQLAlchemy-land, a composite foreign key
(using ForeignKeyConstraint) on Invoice that matches both invoice.xrscust
and invoice.pay2addrid to both of the corresponding columns on
BillingInfo.  The explicit join condition on the relation() would then no
longer be needed (the need to explicitly declare things SQLA should be
figuring out may be considered a code smell here).

--~--~---------~--~----~------------~-------~--~----~
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