On Aug 4, 2010, at 11:51 AM, Richard Kuesters wrote: > thanks Michael, that's what i have in mind. since anon_N can't be used, i was > thinking if they can be named or, in other cases, the sql that generates an > anon_N can be extracted? > > ps: the object that contains these anon_N columns is a orm.Query object > created from a polymorphic mapper with multiple relationships.
What I am saying is, they are already extracted, assuming they are appropriate for use. If these anon's are the product of eagerload()/joinedload(), those aren't available to you. Otherwise, if you show me the scenario, I will show you how the anon_1 is available. > > On Wed, Aug 4, 2010 at 12:29 PM, Michael Bayer <mike...@zzzcomputing.com> > wrote: > > On Aug 4, 2010, at 10:07 AM, Richard Kuesters wrote: > > > hi all, > > > > in a polymorphic query, after a 'print' command i realized that SA > > generates some columns named 'anon_X', which can be helpful for me. > > > > the question is: > > > > 1. is it safe to use those anon_X columns to refine my query? > > --- regarding this, my concern is that once the polymorphic query is done > > by SA, will it anytime change it's name, or anything else in future > > releases? > > it's not. When anonymous aliases are generated within the orm Query against > some entity that you've given it explicitly, you use the column attributes on > that entity to reference those columns, not strings. Never use strings > except for those that you've named explicitly, and at the same level as where > you named it. > > For example, you might use a string if you wanted to ORDER BY some expression > that's named in the columns clause: > > q = sess.query(func.myfunction(...).label('bar')).order_by('bar') > > However, once you nest "q" as a subquery, it gains a .c. collection, and now > you use that .c. collection for all future references to 'bar': > > q = q.subquery() > q2 = sess.query(MyEntity).join((q, q.c.bar==MyEntity.bar)) > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. > > > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@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. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.