Quick question: Why am I allowed to persist an address with no person_id? Shouldn't the delete-orphan prohibit this?
Thanks, Michael from sqlalchemy import Column, Integer, String, ForeignKey, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import scoped_session, sessionmaker, relationship, backref Base = declarative_base() Session = scoped_session(sessionmaker()) def init_model(dsn): engine = create_engine(dsn) Session.configure(bind=engine) Base.metadata.bind = engine Base.metadata.create_all(engine) class Person(Base): __tablename__ = 'person' id = Column(Integer, primary_key=True) name = Column(String(50)) addresses = relationship("Address", backref="person", cascade="all, delete-orphan") class Address(Base): __tablename__ = 'address' id = Column(Integer, primary_key=True) email = Column(String(50)) person_id = Column(Integer, ForeignKey('person.id')) #backref: person init_model('sqlite:///:memory:') s = Session() s.add(Person(name='Isaac')) s.commit() s.add(Address(email='zxksa...@gmail.com')) s.commit() for adr in s.query(Address).all(): print adr.email print adr.person_id ''' Why am I allowed to persist an address with no person_id? Shouldn't the delete-orphan prohibit this? ''' -- 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.