On May 2, 2007, at 2:12 PM, askel wrote:

>
> Hello everyone!
>
> I'm trying to implement deferred property loading using select():
>
> summaries = select(
>   [
>     func.max(transactions.c.processed_at).label('last_used'),
>     func.count(transactions.c.id).label('times_used'),
>   ],
>   from_obj=[transactions],
> ).alias('summaries')
>
> account_mapper = mapper(Account, accounts,
>   properties={
>     'last_used': deferred(summaries.c.last_used, group='summary'),
>     'times_used': deferred(summaries.c.times_used, group='summary')}
> )
>
> How do I specify where clause for summaries?
> I tried to add the following to property list:
>
>   'account_id': [accounts.c.id, transactions.c.account_id],
>
> but that raised an exception:
>
> InvalidRequestError: Given column 'transactions.account_id', attached
> to table 'transactions', failed to locate a corresponding column from
> table 'accounts'
>
> I couldn't find solution other than giving up using properties and
> calling that select directly. But it doesn't  feel right and it seems
> like all it needs is a small addition to make it doing right job.
>

the easiest way to do this would be to map your "summaries" query to  
an object and use relation().  that keeps 'summaries' self contained  
and doesnt force the mapper and its properties to make all kinds of  
guesses and leaps to figure out how those columns should be shoved  
into a deferred select.

every other method youre trying to do, theres fragments of that  
functionality available but ultimately the join between accounts and  
summaries and/or transactions needs to be explicitly stated  
somewhere, either by mapping to accounts.join(transactions) or  
something similar.  deferred() only knows how to select columns from  
the main mapped table it does not know how to express relationships.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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