On Feb 25, 2011, at 7:31 AM, Chris Withers wrote:

> Hi All,
> 
> I have the following models:
> 
> class IP(Base):
>    __tablename__ = 'ip'
>    username = Column(String(50),
>                      ForeignKey('user.username'),
>                      primary_key=True)
>    ip = Column(String(15), primary_key=True, index=True)
> 
> class User(Base):
>    __tablename__ = 'user'
>    username = Column(String(50), primary_key=True)
>    ips = relation("IP",
>                   order_by="IP.ip",
>                   backref="user",
>                   cascade="all")
> 
> If I delete a user as follows:
> 
> session.delete(session.query(User).get('testname'))
> 
> ...then the IPs associated with 'testname' get deleted.
> 
> However, if I do:
> 
> session.query(User).delete()
> 
> ..they do not.
> 
> Why is that?
> How do I get them both to work?

you would need to configure "ON DELETE CASCADE" on the foreign key.  
ForeignKey() offers the "ondelete" option for this.



> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>           - http://www.simplistix.co.uk
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to