[Zope] [ADVANCED] How do YOU guys do many-to-many in Zope without relational?

Thomas B. Passin tpassin@mitretek.org
Tue, 23 Oct 2001 12:44:23 -0400


[Michel Vayssade]

> On Mon, 22 Oct 2001, Max M wrote:
> > I basically have two zClassses. students and subjects. There can be many
> > subjects, and in any subject there can be any number of students.
> .......
>
> in such a case I will do it that way :
>
> each student_object will have a unique id, say "stu_01234"
> each subject_object will have a unique id, say "suj_56789"
>
> each student_object will have a list of subjects were he applied :
> ['suj_56789','suj_567','suj_512',...]
>
> if a subject is deleted
> you can protect your code by :
> creating a global_subject_list (permanet or dynamic)
> global_subject_list.has_key[a_subject]
> or you can write your own "delete_subject" fonction which will
> remove from student lists the delete subject
>
> the uniques ids act has an indirection allowing to modify the object
> without breaking any link

You have to make sure to avoid the classic problem of inadvertently removing
a subject just because no students happen to be taking it just now.  This
may not be a problem for Miche's code but it is easy to happen.

This issues is called "relational integrity" and is a major benefit of using
a relational database - the database can manage these issues.

Cheers,

Tom P