Awesome, thank you much. It is correlated to the parent. The query-
enabled properties section looks interesting to me. Will there be a
significant performance difference between the two approaches? I want
this to be lazily evaluated, so that this information is never fetched
unless we actually request that attribute.

On Mar 16, 3:44 pm, Michael Bayer <mike...@zzzcomputing.com> wrote:
> this kind of pattern is usually handled by column_property(), assuming you 
> can correlate your subquery to the parent within the WHERE clause such that 
> the return value is a scalar.  
>
> Below if you really just wanted "the first row" you'd want to say "limit(1)". 
>   If you really want that exact same first row of the table every time, it 
> would be better as just an additional method or descriptor on your OrderChain 
> object, (or even if not) perhaps even as a class method if the value truly 
> has no correlation to the identity of the parent (which seems unlikely).
>
> Two different strategies at:
>
> http://www.sqlalchemy.org/docs/orm/mapper_config.html#sql-expressions...
>
> http://www.sqlalchemy.org/docs/orm/relationships.html#building-query-...- 
> specific to relationship(), but the same idea could be applied to columns too.
>
> On Mar 16, 2011, at 10:23 AM, hoesley wrote:
>
>
>
>
>
>
>
> > I am trying to create a property on a mapped class which basically
> > executes a subquery. Here is what I'm trying to do in non-working
> > pseudo code:
>
> > mapper(OrderChain,      Table('order_chains',        self.meta,
> > autoload=True),
> >            properties={'entries': relation(OrderChainEntry,
> > order_by=Column('timestamp')),
> >                        'first_cancel':
> > select(OrderChainEntry).filter('type'='new').first()
> > })
>
> > Is something like this possible? Or what's the best way to approach
> > it?
>
> > Also, if I've mangled terminology and/or written something that makes
> > no sense, please let me know - I'm very new to this package!
>
> > Cheers,
> > Andrew
>
> > --
> > 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 
> > sqlalchemy+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://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 sqlalchemy@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.

Reply via email to