Still getting the hang of SQLAlchemy terminology.

I didn't mean a simple deferred() column, but a deferred column_property()
which defines a scalar select(). Like in the example here
http://www.sqlalchemy.org/docs/orm/mapper_config.html#sql-expressions-as-mapped-attributes
.

My goal is to, instead of including a correlated subquery in the SELECT. The
column_property looks like

Customer.num_orders = orm.column_property(
    select([func.count(Order.id)])\
    .where(Order.customer_id == Customer.id)\
    .correlate(Customer.__table__),
    deferred=True
)


I'd rather do a separate query to load num_orders, rather than getting it
lazily or by using undefer(). It almost feels like I might want to define
num_orders as a relationship somehow? I dunno if what I would like to do
maps cleanly to a SQLAlchemy pattern.

On Wed, Sep 7, 2011 at 7:51 AM, Michael Bayer <mike...@zzzcomputing.com>wrote:

> For a deferred() itself, we don't have an option that does this.    Though
> this is an unusual request.   If you definitely want the deferreds to load,
> what's the issue having them render inline into the original query ?    The
> advantage to "subqueryload" is primarily in that it loads multiple rows per
> parent object efficiently, without re-fetching the full parent row many
> times,  or needing to use a less efficient OUTER JOIN.   A deferred is
> always one row per parent - and no join is needed anyway.
>
>
>
>
> On Sep 6, 2011, at 6:49 PM, Sumeet Agarwal wrote:
>
> > I have a collection of deferred `ColumnProperty`s that I'd like to
> > start loading in subsequent queries. I know you can get this to happen
> > on the first access of a `ColumnProperty` that is deferred, but I
> > wonder if there's any way to specify this in the query.
> >
> > For relationships, `joinedload[_all()]` has a counterpart
> > `subqueryload[_all()]`. Is there nothing similar we can do for
> > `ColumnProperty`?
> >
> > --
> > 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.
> >
>
> --
> 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.
>
>

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