yeah if any of those JOINs were LEFT OUTER joins then the combination of INNER 
and OUTER join would not be associative so...it right nests like that.  

On Tue, Nov 3, 2020, at 1:53 PM, Alex Collins wrote:
> Thanks so much! I was interpreting the parenthesis as a subquery. Been 
> banging my head against the wall thinking this was SQLAlchemy nonsense for 
> quite a while and it was just a simple misundertstanding of syntax. Now, I've 
> got the information I should be able to fix this within the far messier 
> application code. 
> On Tuesday, November 3, 2020 at 8:57:18 AM UTC-3:30 Alex Collins wrote:
>> Trying to configure a set of relationships to all be joined loaded and the 
>> particular relationship structure doesn’t seem to want to join. I have a 
>> one-to-many relationship where the many is the child in joined table 
>> inheritance. The foreign key to my source table is on the polymorphic child 
>> table. But, however I configure the relationship it does a subquery instead 
>> of a joined load on the parent class.
>> 
>> Built a test application as a demonstration. What I want is to have the 
>> script below function the same way but, the query at the end outputs a 
>> joinedload for PolyParent instead of a subquery. 
>> 
>> from sqlalchemy import Column, ForeignKey, Integer, Text, create_engine
>> from sqlalchemy.ext.declarative import declarative_base
>> from sqlalchemy.orm import relationship, sessionmaker
>> 
>> Base = declarative_base()
>> 
>> class PolyParent(Base):
>>     __tablename__ = "poly_parent"
>>     id = Column(Integer, primary_key=True)
>>     type = Column(Text)
>>     __mapper_args__ = {"polymorphic_identity": "poly_parent", 
>> "polymorphic_on": type}
>> 
>> class PolyChild(PolyParent):
>>     __tablename__ = "poly_child"
>>     id = Column(Integer, ForeignKey("poly_parent.id"), primary_key=True)
>>     parent_id = Column(Integer, ForeignKey("source.id"))
>>     __mapper_args__ = {"polymorphic_identity": "poly_child"}
>> 
>> class Source(Base):
>>     __tablename__ = "source"
>>     id = Column(Integer, primary_key=True)
>>     children = relationship(PolyChild)
>> 
>> engine = create_engine("sqlite://")
>> session = sessionmaker(bind=engine)()
>> Base.metadata.create_all(bind=engine)
>> 
>> print(session.query(Source).join(Source.children))
> 

> -- 
> 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/dad45bfd-a764-4354-8b6c-fe5ce58db925n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/sqlalchemy/dad45bfd-a764-4354-8b6c-fe5ce58db925n%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/e501d1a4-c303-45e1-a872-97a869a58262%40www.fastmail.com.

Reply via email to