> When you call someRowObject.destroySelf(), and that object is part of
> a many-to-many relationship with another class/table (and some links
> have been made), should destroySelf clean up the now dead links in
> the intermediary table?
>
> For example, I have a Member who can be part of zero or more Groups
> (RelatedJoin field in Member), and a Group can have zero or more
> Members (RelatedJoin in Group).
>
> Unless I'm doing something very wrong (entirely possible), it doesn't
> seem to be removing them. I destroySelf Member objects, and then
> calling the RelatedJoin field in a Group object which referenced the
> destroyed Member throws a sqlobject.main.SQLObjectNotFound exception.
I use the following hack to delete related entities:
def destroySelfPatched(join):
"""A workaround against default SQLObject's behaviour where the entries in
intermediate table are not deleted when original object is destroyed.
"""
tableName = join.kw['intermediateTable']
joinColumn = join.kw['joinColumn']
def wrapper(self):
cls = self.__class__
super(cls, self).destroySelf()
sql = "DELETE FROM %s WHERE %s = %d" % \
(tableName, joinColumn, self.id)
self._connection.query(sql)
return wrapper
class Something(SQLObject):
tags = RelatedJoin('Tag', ...)
destroySelf = destroySelfPatched(tags)
Crude hack and supports a single join only but it works for me.
Regards,
Max.
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss