On Mar 30, 2014, at 1:55 PM, Jonathan Vanasco <[email protected]> wrote:

> I have a handful of queries that are fairly complex.
> 
> For these, I need to support both 
> 
>      SELECT object.*   ( for full records )
>      SELECT object.id   ( for caching of collection ids + COUNT operations )
> 
> My current approach is really dirty.  three functions wrap a "core" 
> generator, which does all the heavy work.  They just pass in the kwargs.
> 
> I don't really like this, because the 'core' starts like this:
> 
>     if ids_only or for_count:
>         query = dbSession.query( Object.id )
>     else:
>         query = dbSession.query( Object )
> 
> I generally don't like writing things that behave so differently.
> 
> Is it possible to query Object, build all the joins/filters against that, and 
> then just edit the query to only select the 'id' afterwards ?

yes this is in the docs, replace_columns() or something like that

of course I'm never 100% sure its there so i have to look, and it is, 
with_entities:

http://docs.sqlalchemy.org/en/rel_0_9/orm/query.html?highlight=query#sqlalchemy.orm.query.Query.with_entities


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to