[Sqlalchemy-tickets] Issue #3845: back_populates does not work with lazy="noload" (zzzeek/sqlalchem
Brought to you by:
zzzeek
From: Yegor R. <iss...@bi...> - 2016-11-06 10:48:24
|
New issue 3845: back_populates does not work with lazy="noload" https://bitbucket.org/zzzeek/sqlalchemy/issues/3845/back_populates-does-not-work-with-lazy Yegor Roganov: Other side of relationship is not populated when relationship declared with `lazy="noload"`, though it works with `lazy=True`. If this is by design, docs should probably mention this. Here is the code: ``` #!python from sqlalchemy import Column, Integer, ForeignKey from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import relationship Base = declarative_base() class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) addresses = relationship("Address", lazy="noload", back_populates="user") class Address(Base): __tablename__ = 'addresses' id = Column(Integer, primary_key=True) user_id = Column('user_id', Integer, ForeignKey('users.id')) user = relationship("User") a1 = Address() u = User() u.addresses.append(a1) assert a1.user == u ``` |