The name is on account, not on entry.
Transactions and all must be loaded in one shot starting from a single
account:

account (e.g. id=7)
     ==> all its entries
===> one Transaction for each entry ==> all entries of each
transaction (some are different than first ones) ==> the account of
each entry

I need all of this data retrieved in a single SQL SELECT, to be sent
in a web page for listing the content of an account.
If possible, i don't want to execute a separate select ACCOUNT.

On 11 sep, 16:12, Michael Bayer <[EMAIL PROTECTED]> wrote:
> if you just want the Account object and the names of the entries
> separately, you can skip any eager loading and do an add_column such as:
>
> acc = session.query(Account).add_column
> (table_entries.c.name).outerjoin('entries').filter_by
> (Account.account_id==77)
>
> I dont see Transaction being loaded here since thats linked to an
> Entry object, which you said you didnt want to load.
>
> On Sep 11, 2007, at 5:28 AM, Jean-Philippe Dutreve wrote:
>
>
>
> > Here's my issue: 3 tables
>
> > CREATE TABLE accounts (
> >     account_id serial PRIMARY KEY,
> >     name varchar(16) NOT NULL UNIQUE,
> > );
> > CREATE TABLE transactions (
> >     transaction_id serial PRIMARY KEY,
> > );
> > CREATE TABLE entries (
> >     entry_id serial PRIMARY KEY,
> >     account_id integer NOT NULL REFERENCES accounts,
> >     transaction_id integer NOT NULL REFERENCES transactions,
> > );
>
> > A Transaction links Account together with Entries, Transaction should
> > eager load its entries and their account.
>
> >     mapper(Account, table_accounts)
> >     mapper(Transaction, table_transactions)
> >     mapper(Entry, table_entries, properties = dict(
> >         account     = relation(Account, uselist=False,
> > backref=backref('entries', lazy=True)),
> >         transaction = relation(Transaction, uselist=False,
> > backref=backref('entries', lazy=False, join_depth=3)),
> >     ))
>
> > I just want to retrieve in one SELECT all tx engaged and the
> > account.name of each entry:
>
> > acc =
> > session.query(Account).options(eagerload_all
> > ('entries.transaction.entries.account')).get(7)
> > acc.entries[1].transaction.entries[1].account.name <== execute a new
> > SELECT to retrieve all entries of this account (different than
> > account_id=7)
>
> > SELECT *
> > FROM (SELECT accounts.account_id AS accounts_account_id,
> > accounts.account_id AS accounts_oid FROM jdu.accounts WHERE
> > accounts.account_id = 77 ORDER BY accounts.account_id  LIMIT 1 OFFSET
> > 0) AS tbl_row_count, jdu.accounts
> > LEFT OUTER JOIN jdu.entries AS entries_3 ON accounts.account_id =
> > entries_3.account_id
> > LEFT OUTER JOIN jdu.transactions AS transactions_1 ON
> > transactions_1.transaction_id = entries_3.transaction_id
> > LEFT OUTER JOIN jdu.entries AS entries_2 ON
> > transactions_1.transaction_id = entries_2.transaction_id
> > WHERE accounts.account_id = tbl_row_count.accounts_account_id ORDER BY
> > tbl_row_count.accounts_account_id, entries_3.entry_id,
> > transactions_1.transaction_id, entries_2.entry_id
>
> > But I don't need any of entries of account 77, I just want its name
> > (to be sent on a remote web client).
>
> > Thanks for any help,
> > jp


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to