[ZODB-Dev] Referential integrity

Arnaud Bienvenu arnaud.bienvenu@makina-corpus.org
Fri, 1 Mar 2002 16:39:54 +0100


On Fri, Mar 01, 2002 at 09:47:37AM -0500, Jim Fulton wrote:
> What list? There is no way to explicitly remove
> an object from the database.  An object will be removed
> from the database when it is no longer referenced.

I understand that, but I want to set up constraints in my model, like people
do with relational databases using foreign keys.

Here is an example : imagine we have two classes : Person and
Country. On the one hand, we have a pool of today's world countries, with
their name and other attributes. This pool may be a list, a dictionnary, or
any sequence you want. On the other hand, each Person instance refers to one
Country instance that is part of the pool.

Now imagine some country disappears : the person in charge of maintaining
the list of countries up to date will remove it from the pool. I would like
something to happen for every Person instance that refers to this country,
because I don't want them to refer to some country that is not in the
official list.

In PostgreSQL terms :
CREATE TABLE person (id INT4 PRIMARY KEY, lastname TEXT,
country INT4 REFERENCES countries);
CREATE TABLE countries (id INT4 PRIMARY KEY, name TEXT);

(here I can't remove a country if it is referenced by a person)

My question is : what is the best way to get this behaviour using ZODB (or
maybe another OODB)

Thanks to Steve, Greg and Patrick for their very interesting suggestions.
-- 
Arnaud Bienvenu
http://www.makina-corpus.org/