Also, there are some restrictions in my setup such that I am not able to use eager load like session.query(Engineer).options(joinedload(...)).get(). I retrieve the engineer object using another relationship.
On Thursday, November 28, 2019 at 5:45:46 PM UTC+8, Carson Ip wrote: > > Hi Mike, > > I have having issues letting a subclass load a parent's relationship that > configured lazy="joined". > > Let's say Engineer is a subclass of Person, and Person stores "company_id" > and has a relationship called "company" that is lazy="joined". > > Although I don't have a minimal reproducible example now, but in my setup, > let's say: > engineer = session.query(Engineer).get(1) # emits 1 query > engineer.company # emits another query > > I suspect that the subclass does not respect parent class' relationship > lazy/eager loading options. > > Also I bump into this issue when identity map remembers the id's > polymorphic type. Then when I query on the base class, it emits the the > subclass query and does not load the parent class' relationship with eager > load options, which is the problem I mentioned. > engineer = session.query(Engineer).get(1) > session.commit() > person = session.query(Person).get(1) # emits 1 query > person.company # emits another query > > > > Is this by design? If so, is there any way to make it respect parent > class' relationship "lazy" option? > > I am not 100% certain this is reproducible in a simple example. There may > be problems in my setup that would cause this. Please let me know if this > is the case. > > Thanks in advance. > -- 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/e113353b-9453-462d-99a9-a93f517873bd%40googlegroups.com.