Closed
Description
Migrated issue, originally created by Michael Bayer (@zzzeek)
kind of a big oversight...
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class A(Base):
__tablename__ = 'a'
id = Column(Integer, primary_key=True)
data = Column(String)
bs = relationship("B", back_populates="a")
class B(Base):
__tablename__ = 'b'
id = Column(Integer, primary_key=True)
a_id = Column(ForeignKey("a.id"))
data = Column(String)
a = relationship("A", back_populates="bs")
e = create_engine("sqlite://", echo=True)
Base.metadata.create_all(e)
s = Session(e)
b1 = B()
a1 = A(bs=[b1])
s.add_all([a1, b1])
s.commit()
b1.a
del b1.a
s.commit()
assert b1.a is None
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
sqlalchemy-bot commentedon Nov 2, 2018
Michael Bayer (@zzzeek) wrote:
Implement delete
A long-standing oversight in the ORM, the
__delete__
method for a many-to-one relationship was non-functional, e.g. for an operation such as
del a.b
. This is now implemented and is equivalent to setting the attributeto
None
.Fixes: #4354
Change-Id: I60131a84c007b0bf6f20c5cc5f21a3b96e954046
→ 2e2af8d
sqlalchemy-bot commentedon Nov 2, 2018
Changes by Michael Bayer (@zzzeek):