On 4/24/07, Gaetan de Menten <[EMAIL PROTECTED]> wrote:
> On 4/23/07, Michael Bayer <[EMAIL PROTECTED]> wrote:
> >
> >
> > On Apr 23, 2007, at 3:49 PM, Gaetan de Menten wrote:
> >
> > > Hello there,
> > >
> > > In a mapped object, is there any way to map a scalar attribute to an
> > > arbitrary selectable/subquery?
> > >
> > > Jonathan Ellis demonstrated how to do that for relations on this page:
> > > http://spyced.blogspot.com/2007/01/why-sqlalchemy-impresses-me.html
> > >
> > > I'd like to do that for scalars.
> > >
> > > I've thought about using a property returning a query, but this still
> > > generates one query per user (my mapped object) and I need to do
> > > everything in one pass.
> > >
> > > See attached file for an example of what I'd like to do.
> > >
> > > I've the feeling it might already be possible but I don't see how. If
> > > it's not possible yet, do you have any pointer how I could implement
> > > that?
> > >
> >
> > there are probably three general ways to do what youre doing there.
>
> Thanks for the quick answer!
>
> > the oldest way is something i did in the zblog demo before SA 0.1 was
> > released, which is that you map to the full query you want:
> >
> > s = select([users_table, func.sum(tags_table.c.score1 *
> > tags_table.c.score2).label('score')],
> > users_table.c.user_id==tags_table.c.user_id, group_by=[c for c in
> > users_table.c])
> >
> > mapper(User, s)
> >
> > the effect above is that your func() becomes another ColumnProperty.
>
> That's what I was looking for. So simple... and I didn't think of it. Damn...

Hmmm, on second thought, it's not enough for my needs. I need to be
able to defer that "column" and undefer it per query. I know I could
use several mappers with entity_names but since I'll have several such
"columns", it'll be too much trouble to create an alternate mapper for
each and every possible combination of those "columns" being deferred
or not. So I guess I'll need to use the ugly intermediary class
solution for now.

-- 
Gaƫtan de Menten
http://openhex.org

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