from sqlalchemy import Column, ForeignKey, Integer, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import lazyload, relationship, sessionmaker
Base = declarative_base() class Group(Base): __tablename__ = 'groups' id = Column(Integer, primary_key=True) users = relationship('User', lazy='raise') class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) group_id = Column(Integer, ForeignKey('groups.id')) engine = create_engine('sqlite:///:memory:', echo=True) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) session = Session() group = Group() session.add(group) session.commit() group = session.query(Group).options(lazyload(Group.users)).first() print('SUCCESS', group.users) session.refresh(group) print('FAILURE', group.users) Is `session.expire(group)` is the only way to reload collections and related items? -- 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/43ce8eb9-367d-43da-a371-0fa5e157e0de%40googlegroups.com.