try calling:

query(C.symbol_from_a).select_from(C)



On Wed, Nov 10, 2021, at 4:50 AM, niuji...@gmail.com wrote:
> class A(Base):
>     primary_id = Column(Integer, prirmary_key=True)
>     some_A_marker = Column(String)
> 
> class B(Base):
>     primary_id = Column(Integer, primary_key=True)
>     referencing_A_id = Column(Integer, ForeignKey(A.primary_id))
> 
> class C(Base):
>     primary_id = Column(Integer, primary_key=True)
>     basedOn_B_id = Column(Integer, ForeignKey(B.primary_id))
>     symbol_from_A = column_property(
>            
> sasql.select(A.some_A_marker).select_from(A).join(B).where(B.primary_id == 
> C.basedOn_B_id).correlate(C).scalar_subquery().label("symbol_from_A")
>        )
> 
> 
> When I query this highlighted column_property along with the whole object, it 
> works fine:
> 
> >>> sess.query(C, C.symbol_from_A).all()
> 
> However, when I query this column_property alone, it doesn't work:
> 
> >>>sess.query(C.symbol_from_A).distinct().all()
> 
> I noticed that somehow the correlated subquery wasn't executed property when 
> query that column_property independently.
> 
> How to solve this?
> 
> 
> 
> -- 
> SQLAlchemy - 
> The Python SQL Toolkit and Object Relational Mapper
>  
> http://www.sqlalchemy.org/
>  
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sqlalchemy/f7a0c360-ada2-456b-b02a-498ca50334f3n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/f7a0c360-ada2-456b-b02a-498ca50334f3n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/d23fa6bc-c5db-44d6-9416-a4f169df20da%40www.fastmail.com.

Reply via email to