On 09/12/2010 04:27 PM, Michael Bayer wrote: > cant speak for Elixir, but your "passive_deletes" is on the wrong side in > your declarative example. > > The correlations between classical and declarative relationship patterns are > now individually contrasted at > http://www.sqlalchemy.org/docs/orm/relationships.html#basic-relational-patterns > . > > On Sep 11, 2010, at 10:58 PM, alex bodnaru wrote: > >> On 09/11/2010 04:31 AM, alex wrote: >>> On 09/10/2010 05:41 PM, Michael Bayer wrote: >>>> On Sep 10, 2010, at 4:13 AM, alex wrote: >>>> >>>>> hello friends, >>>>> >>>>> as sqlite has recently introduced support for on delete/update cascade, >>>>> i'd like to implement the passive_* functionality for this driver too. >>>>> >>>>> please give me a hint where to start. >>>> passive_delete and passive_update are database agnostic and only apply to >>>> what effects the ORM can expect from the underlying schema, just use them >>>> normally. >>>> >>> thanks a lot for your response michael. >>> i spent a little time to make a more isolated test case, and it works with >>> sa+orm, but not with elixir, that seems to forget to pass the >>> passive_deletes. >>> i'm further inquiring there, in a hope to make a patch. >>> >>> best regards, >>> alex >> one further step took me closer to the problem. it happens with declarative >> too. >> i'm attaching 3 scripts for comparison: one made with regular orm, one with >> elixir and one with declarative. the same problem with elixir and >> declarative. >> haven't tested on other rdbms. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sqlalchemy" group. >> To post to this group, send email to sqlalch...@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. >> >> <cascade_declarative.py><cascade_elixir.py><cascade_orm.py> btw, the fixed code.
-- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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 (MetaData, Table, Column, Integer, String, ForeignKey, create_engine, ForeignKeyConstraint) from sqlalchemy.orm import scoped_session, sessionmaker, relation from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.interfaces import PoolListener class SQLiteFKListener(PoolListener): def connect(self, dbapi_con, con_record): dbapi_con.execute('PRAGMA foreign_keys = ON;') engine = create_engine("sqlite:///:memory:", echo=True, listeners=[SQLiteFKListener()]) Base = declarative_base(bind=engine) class MyClass(Base): __tablename__ = 'mytable' id = Column(Integer, primary_key=True, autoincrement=True) name = Column(String(50)) children = relation('MyOtherClass', backref='parent', passive_deletes=True) def __repr__(self): return '<MyClass %s, "%s">' % ("None" if self.id is None else str(self.id), self.name) class MyOtherClass(Base): __tablename__ = 'myothertable' id = Column(Integer, primary_key=True, autoincrement=True) parent_id = Column(Integer, ForeignKey('mytable.id', ondelete="CASCADE")) name = Column(String(50)) def __repr__(self): return '<MyOtherClass %s, %s, "%s">' % ("None" if self.parent_id is None else str(self.parent_id), "None" if self.id is None else str(self.id), self.name) Base.metadata.create_all(engine) session = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=engine)) alex = MyClass(name='alex') pisi = MyClass(name='pisi') session.add_all([ alex, pisi ]) print alex, pisi session.flush() session.add_all([ MyOtherClass(parent=alex, name='dagan'), MyOtherClass(parent=alex, name='shaked'), MyOtherClass(parent=pisi, name='dagan'), MyOtherClass(parent=pisi, name='shaked'), ]) session.flush() shaked1 = session.query(MyOtherClass).filter_by(parent_id=1, name=u'shaked') session.delete(alex) session.flush() for my in session.query(MyClass).all(): print my for my in session.query(MyOtherClass).all(): print my