On Sun, Feb 2, 2014 at 11:00 AM, Michael Bayer <[email protected]>wrote:
>
> So besides the “use_labels” part, the other thing that can make it work in
> 0.9.1 is to link the statement to the mapped Column objects themselves:
>
> from sqlalchemy.sql.selectable import TextAsFrom
> TextAsFrom.use_labels = True
>
> s.query(User).from_statement(
> text("select * from users order by id").\
> columns(User.id, User.name)
> )
>
Fantastic, that worked great! In the actual stored procedure I was working
with the column names were different (e.g.
"ODSQuery_tblLoadBoard_BookedById" rather than "BookedById"), so I ended up
using label() on each column before sending it to columns(). Also, the
first three arguments to query() there are composite properties, and the
last one is from a separate table.
def _trackable_truckload_details():
text = db.text("EXEC ODSQuery.SelectBridgeLoadBoard")
cols = [col for col in LoadBoard.__table__.c]
cols = map((lambda x: label('ODSQuery_tblLoadBoard_' + x.name, x)),
cols)
mobile_cols =
LoadMobileTracking.load_mobile_tracking_id.property.columns
mobile_cols = map((lambda x: label('LoadMobileTracking_' + x.name, x)),
cols)
cols.extend(mobile_cols)
taf = text.columns(*cols)
return db.session.query(
LoadBoard.load,
LoadBoard.orgn_stop,
LoadBoard.dest_stop,
LoadMobileTracking.load_mobile_tracking_id).from_statement(taf).all()
Actually, I'm pretty surprised it worked at all before, without the
labeling. How did it figure out which result set columns went to which ORM
object?
> I’m committing 2932 in a moment and I’m super really hoping I can put out
> 0.9.2 today but it’s easy for me to run out of time, but 0.9.2 is
> definitely due.
>
That would be awesome! Incidentally though, would this labeling still work
once the fix is in?
Thanks for all your help,
Matt
--
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/groups/opt_out.