-QH-
-Rob
Just alther the tables that sqlobject automagically creates. I.e. I
have a RelatedJoin between Person and Keyword. Using tg-admin sql sql
I can see that the intermediate table between Person and Keyword that
sqlobject would create looks like this:
CREATE TABLE keyword_person (
keyword_id INT NOT NULL,
person_id INT NOT NULL
);
Then I just alter it to add the foreign key contraints:
alter table keyword_person
add foreign key (keyword_id) references keyword(id) on delete cascade;
alter table keyword_person
add foreign key (person_id) references person(id) on delete cascade;
It's dirt simple.
--
mvh Björn
Nope, I hadn't. About the only thing I know about transactional
databases is that they are generally considered a good thing. I'm
pretty new to working with DB programming, and all of my expereince has
been with ones that don't support transactions so using that feature is
somehwat outside of my ken. I'll look into it though, thanks for the
suggestion.
-QH-
<snip useful example stuff>
I had no idea tg-admin could let me look at that sort of stuff. Handy.
In other "framework" systems I've worked with, directly manipulating
the "automagic" elements had a tendency to break stuff so I've learned
to avoid it. So, if that's not the case with TG, you're right, it's
dirt simple. Thanks!
-QH-
-Rob
>
> This solution is a more fleshed out version of my solution. You need a
> DB which supports ON DELETE CASCADE, which generally are
> transactional.
> MySQL with InnoDB tables supports this, PostGres will almost certainly
> support this, however I'm not so sure about SQLite.
Yep, Postgres surely does.
Alberto
def destroySelfPatched(join):
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
And
class Foobar(SQLObject):
tags = RelatedJoin(...)
destroySelf = destroySelfPatched(tags)