Hi, Currently I am trying to implement a feature that transfers all products in a store to another store, and then destroy the old store which contains no product. The sqlalchemy version is 0.6.8.
class Product(PolymorphicClass): #there are different types of the product __tablename__ = "products" id = Column("id", Integer, primary_key=True, key="id") name = Column("name", String(50), unique=True, nullable=False) storeId = Column("store_id", Integer, ForeignKey("store.id"), key="storeId") store = relationship("Store", uselist=False, backref=backref("_products", collection_class=set, cascade="all, delete")) class Store(object): __tablename__ = "stores" id = Column("id", Integer, primary_key=True, key="id") name = Column("name", String(50), unique=True, nullable=False) I tried to use query object to update the storeId column in the Product class, like: session.query(Product).filter(Product.storeId==oldStoreId).update({Product.storeId: newStoreId}) but the sqlalchemy rejected this with the "Only update via a single table query is currently supported" message. So then I decided to use session.execute(Product.__table__.values().where()) to update the table and it works fine. But in the final step "deleting old store", I tried to delete the store object(now the store has no product after the update), and the store object is deleted...but with the products that "previously" belong to this store. I guess the cascade delete in the relationship does not notice if I use session.execute() to update the table. So my question is...(1) Is there anyway to tell the relationship "hey now those products no longer belong to you, and you shouldn't delete them when you are to deleted"? (2) Is there any trick, even the polymorphic class can use the query object to update table, without getting "Only update via a single table query" error? I still prefer to use session.query() instead of session.execute()... Thank you very much, and happy new year! -- 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.