Sorry, for the spamming, code typo (was trying to simplify it), should read:
invoices = query(ArkInvoice).\ join(ArkInvoice.project).\ join(ArkProject.client).\ options(sa.orm.contains_eager(ArkInvoice.project.client)).\ filter(ArkInvoice.project.client.id == id) On Thu, Jun 9, 2011 at 8:50 AM, Jules Stevenson <droolz...@googlemail.com> wrote: > I don't think the info I sent last night was particularly clear, > apologies it was late. The code for the classes is below: > > # ArkClient - clientprojectshot module > orm.mapper(ArkClient, clients_table, properties={ > 'contacts':orm.relation(ArkContact, > backref='client'), > 'projects':orm.relation(ArkProject, > backref='client', > cascade="all, delete, delete-orphan") > }) > > # ArkProject - clientprojectshot module > orm.mapper(ArkProject, projects_table, properties={ > 'contacts': orm.relation(ArkContact, > secondary=project_contact_table, > backref='projects'), > 'invoices':orm.relation(ArkInvoice, > backref='project', > cascade="all, delete"), > 'shots':orm.relation(ArkShot, > backref='project', > cascade="all, delete, delete-orphan"), > 'users':orm.relation(ArkUser, > backref='projects', > secondary=user_projects_primary_table) > }) > > # ArkInvoice - invoices module > orm.mapper(ArkInvoice, invoices_table, properties={ > 'entries': orm.relation(ArkInvoiceEntry, > secondary=invoice_entries_primary_table, > backref='invoice', > cascade="all, delete"), > 'user': orm.relation(ArkUser, backref='invoice'), > 'child_invoices':orm.relation(ArkInvoice, > backref=backref('parent_invoice', > remote_side=[invoices_table.c.id]), > cascade="all", > lazy=False, > join_depth=3) > }) > > What I am trying to do is query the client of an invoice, and to do > this I need to build a query something along the lines of: > > invoice > project > client, and filter by client, or at least I thnk I > need to do this. > > So the current query code I have looks something like this: > > invoices = query(ArkInvoice).\ > join(ArkInvoice.project).\ > join(ArkProject.client).\ > > options(sa.orm.contains_eager(model.ArkInvoice.project.client)).\ > filter(model.ArkInvoice.project.client.id == id) > > But this doesn't work, and I've tried many variations around this > theme with no joy. I'm clearly missing something fundamental, but I'm > not sure what. Any pointers gratefully received. > > Many thanks, > > Jules > > > On Wed, Jun 8, 2011 at 9:56 PM, Jules Stevenson > <droolz...@googlemail.com> wrote: >> sorry, hit the send button a little too soon. >> >> Any help on the above much appreciated, >> >> Jules >> > -- 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.