Hello,
I am using SA 0.6.9 at the moment and get a StaleDataError if I run the
code attached. In 0.7 it works without error. I wanted to understand
what’s changed and have browsed Trac and the migration guide, but only
came across similar looking issues (like
http://www.sqlalchemy.org/trac/ticket/2403
http://www.sqlalchemy.org/trac/wiki/07Migration#Flushingoforphansthathavenoparentisallowed).
The new behaviour fits me better, but I would like to understand what
was wrong with my code before.
Cheers
Sebastian
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.
from sqlalchemy import create_engine, Column, ForeignKey, Integer
from sqlalchemy.orm import sessionmaker, relationship
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite:///:memory:', echo = True)
Base = declarative_base()
Base.metadata.bind = engine
Session = sessionmaker(bind = engine)
class Delivery(Base):
__tablename__ = 'Deliveries'
id = Column(Integer, primary_key = True)
submissions = relationship('Submission', back_populates = 'delivery', cascade = "all, delete-orphan")
class Submission(Base):
__tablename__ = 'Submissions'
id = Column(Integer, primary_key = True)
delivery_id = Column(Integer, ForeignKey('Deliveries.id'), nullable = False)
delivery = relationship('Delivery', back_populates = 'submissions')
Base.metadata.create_all()
session = Session()
d = Delivery()
s = Submission()
session.add(d)
d.submissions.append(s)
session.commit()
print d.id, d.submissions
session.delete(s)
print session.query(Delivery).all()
session.delete(d)
session.commit()