"flatten" model columns in Row

89 views
Skip to first unread message

sector119

unread,
Nov 19, 2022, 5:31:21 PM11/19/22
to sqlalchemy
Hello

For example I have two models X and Y, I want to get all columns from X model and only one or two cols from Y model in the same Row as
[(x_col1, x_col2, x_col3, y_col1), ...] but not [(X, y_col1)] as I get when I perform
select(X, Y.col1).join(X.y)

I just don't want to write all X model cols down at the select statement and just one from Y model like select(X.col1, X.col2, X.col3, Y.col1), X model has plenty of cols, and I'm lazy )

Thanks

Mike Bayer

unread,
Nov 20, 2022, 9:31:09 AM11/20/22
to noreply-spamdigest via sqlalchemy
the quickest way at the moment is to use select(X.__table__, y_col), or, if you use select(X), you can execute from session.connection().execute().
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
 
 
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description.
---
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 sqlalchemy+...@googlegroups.com.

sector119

unread,
Nov 20, 2022, 3:54:10 PM11/20/22
to sqlalchemy
Thank you, Mike!

воскресенье, 20 ноября 2022 г. в 16:31:09 UTC+2, Mike Bayer:
Reply all
Reply to author
Forward
0 new messages