Hi all,
I try to set up a many-to-many relation with an association object.

But I want something not usual: I want the child object deleted when
not owned by any parent anymore.
This is for a messages/recipients relation: the message is useless
when everybody removed it from its mailbox!

I tried that, but it doesn't work:

class Parent(meta.DeclarativeBase):
    id = Column(types.Integer, primary_key=True)

class Child(meta.DeclarativeBase):
    id = Column(types.Integer, primary_key=True)

class Assoc(meta.DeclarativeBase):
    p_id = Column(types.Integer,
                  ForeignKey(Parent.id))
    c_id = Column(types.Integer,
                  ForeignKey(Parent.id))

    parent = relation(Parent,
                      backref=backref('children',
                                cascade='all, delete-orphan'))
    child = relation(Child,
                     backref='parents',
                     cascade='delete-orphan')

I expect "child = relation(Child, backref='parents', cascade='delete-
orphan')" to forward deletes to child when it is an orphan. But it
looks like it forward the delete even if it is not an orphan yet...

It that configuration:

   p1 = Parent()
   p2 = Parent()
   c = Child()
   assoc1 = Assoc(parent=p1, child=c)
   assoc2 = Assoc(parent=p2, child=c)

p1.children = [ ] will lead to:
- delete assoc1 (ok)
- delete c (not ok)
- update assoc2.c_id = null (not ok)

So why is it not really a delete-orphan? :)

Thanks

GustaV
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to