from sqlalchemy import Table, Column, Integer, ForeignKey, create_engine
from sqlalchemy.orm import relationship, sessionmaker, selectinload
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
child_id = Column(Integer, ForeignKey('child.id'))
child = relationship("Child")
class Child(Base):
__tablename__ = 'child'
id = Column(Integer, primary_key=True)
engine = create_engine('sqlite://')
engine.echo = True
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
db=Session()
# create some data
c1 = Child()
db.add(c1)
for n in range(10):
p = Parent(child=c1)
db.add(p)
db.commit()
l = db.query(Parent).options(selectinload(Parent.child)).all()SELECT parent.id AS parent_id, parent.child_id AS parent_child_id FROM parent
SELECT parent_1.id AS parent_1_id, child.id AS child_id
FROM parent AS parent_1 JOIN child ON child.id = parent_1.child_id
WHERE parent_1.id IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
ORDER BY parent_1.idSELECT child.id AS child_id
FROM child
WHERE id IN (1)
--SQLAlchemy -The Python SQL Toolkit and Object Relational MapperTo 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.To post to this group, send email to sqlal...@googlegroups.com.Visit this group at https://groups.google.com/group/sqlalchemy.To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/b199fba3-8aaf-4e23-b406-865c3e57986c%40googlegroups.com.For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlal...@googlegroups.com.
Thank you for your help.I'd be happy to submit a PR (I've already tried to fix this by myself), but the code is a little hard to master.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit https://groups.google.com/d/msgid/sqlalchemy/efc5ccd1-e94a-4b13-909e-62063325f332%40googlegroups.com.