[ADVANCED] How do YOU guys do many-to-many in Zope without relational?
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope. I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students. What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects. So if this was an ordinary relational db it would be many to many. Now I considder making a global student list and then do a recursive search for subjects in the site, so that each student can be related to a subject with a selectbox or somesuch. But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated. I have never seen it used, but would it be possible to store the "global object id" in a list in a user object, and then get the path to the subject object from that? Or should I make the subject a global list to? That way I only have to check if the object exists or not. Not where it is in the object hierachy. This sort of defeats the purpose of Zope's tree like structure. Doesn't it? So, how do YOU guys do many-to-many in Zope ? regards Max M Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
On Mon, 22 Oct 2001, Max M wrote:
So, how do YOU guys do many-to-many in Zope ?
In a relational DB and using ZSQL Methods to retrieve data. -- Joel BURTON | joel@joelburton.com | joelburton.com | aim: wjoelburton Independent Knowledge Management Consultant
At 03:48 PM 10/22/2001 -0400, Joel Burton wrote:
On Mon, 22 Oct 2001, Max M wrote:
So, how do YOU guys do many-to-many in Zope ?
In a relational DB and using ZSQL Methods to retrieve data.
You might want to have a look at DBObjects at http://demo.iuveno-net.de which connects the strengths of relational and object oriented databases. Regards, Stephan -- Stephan Richter CBU - Physics and Chemistry Student Web2k - Web Design/Development & Technical Project Management
I just completed a similar project linking 2 Zclasses to cross-reference each other. I would like to see another reply to your Q to soft-link zclass instances rather than using a programmatic list.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
Allow someone to rename the "title" property, but not change the ID of the Zclass instance (lock the ID once it is created, so users cant rename it). This will retain link integrity. If they delete the instance, then there is no relationship to maintain anyway, so who cares, or create a Subject "status" property to throw up an exception to notate that the Subject is in "delete" status without deleteding the instance. -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Max M Sent: Monday, October 22, 2001 3:44 PM To: Zope@Zope. Org Subject: [Zope] [ADVANCED] How do YOU guys do many-to-many in Zope without relational?
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope.
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects.
So if this was an ordinary relational db it would be many to many.
Now I considder making a global student list and then do a recursive search for subjects in the site, so that each student can be related to a subject with a selectbox or somesuch.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
I have never seen it used, but would it be possible to store the "global object id" in a list in a user object, and then get the path to the subject object from that?
Or should I make the subject a global list to? That way I only have to check if the object exists or not. Not where it is in the object hierachy.
This sort of defeats the purpose of Zope's tree like structure. Doesn't it?
So, how do YOU guys do many-to-many in Zope ?
regards Max M
Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Oh yeah! Zclasses instances dont include "title"s. You have to instantiate themselves in the "property sheet" or elsewhere.
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Trevor Toenjes Sent: Monday, October 22, 2001 3:58 PM To: Max M; Zope@Zope. Org Subject: RE: [Zope] [ADVANCED] How do YOU guys do many-to-many in Zope without relational?
I just completed a similar project linking 2 Zclasses to cross-reference each other. I would like to see another reply to your Q to soft-link zclass instances rather than using a programmatic list.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
Allow someone to rename the "title" property, but not change the ID of the Zclass instance (lock the ID once it is created, so users cant rename it). This will retain link integrity.
If they delete the instance, then there is no relationship to maintain anyway, so who cares, or create a Subject "status" property to throw up an exception to notate that the Subject is in "delete" status without deleteding the instance. -Trevor
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Max M Sent: Monday, October 22, 2001 3:44 PM To: Zope@Zope. Org Subject: [Zope] [ADVANCED] How do YOU guys do many-to-many in Zope without relational?
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope.
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects.
So if this was an ordinary relational db it would be many to many.
Now I considder making a global student list and then do a recursive search for subjects in the site, so that each student can be related to a subject with a selectbox or somesuch.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
I have never seen it used, but would it be possible to store the "global object id" in a list in a user object, and then get the path to the subject object from that?
Or should I make the subject a global list to? That way I only have to check if the object exists or not. Not where it is in the object hierachy.
This sort of defeats the purpose of Zope's tree like structure. Doesn't it?
So, how do YOU guys do many-to-many in Zope ?
regards Max M
Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
From: Trevor Toenjes [mailto:zope@toenjes.com]
Allow someone to rename the "title" property, but not change the ID of the Zclass instance (lock the ID once it is created, so users cant rename it). This will retain link integrity.
again this assumes that the id is unique for all of the site. regards Max M
Good job in explaining some places where relational databases are strong. Tom P [Max M]
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope.
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects.
So if this was an ordinary relational db it would be many to many.
Now I considder making a global student list and then do a recursive search for subjects in the site, so that each student can be related to a subject with a selectbox or somesuch.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
I have never seen it used, but would it be possible to store the "global object id" in a list in a user object, and then get the path to the subject object from that?
Or should I make the subject a global list to? That way I only have to check if the object exists or not. Not where it is in the object hierachy.
This sort of defeats the purpose of Zope's tree like structure. Doesn't it?
So, how do YOU guys do many-to-many in Zope ?
On Monday 22 October 2001 03:44 pm, Max M allegedly wrote:
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope.
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects.
So if this was an ordinary relational db it would be many to many.
Now I considder making a global student list and then do a recursive search for subjects in the site, so that each student can be related to a subject with a selectbox or somesuch.
But if someone renames, deletes or moves a subject I am f.*?d Or the student is. The relation to the subject is invalidated.
I have never seen it used, but would it be possible to store the "global object id" in a list in a user object, and then get the path to the subject object from that?
Or should I make the subject a global list to? That way I only have to check if the object exists or not. Not where it is in the object hierachy.
This sort of defeats the purpose of Zope's tree like structure. Doesn't it?
So, how do YOU guys do many-to-many in Zope ?
regards Max M
They way to do this is to create a lines property in the student and store the ids of the related subjects there. You use a ZCatalog and a keyword index on this property to quickly find which students belong to which subject. Now, this won't fix the renaming issue (although it does fix relocating, assuming the ids are otherwise unique), but you could get around that two ways: 1. Don't rename! Treat the id as the primary key of the subject. 2. Assign another fixed key as a property (or general attribute) of the subject for use as the unique identifier and don't ever change it for the life of the object. You will need to use a ZCatalog to make lookups on this id efficient, but this would allow you to put the object anywhere you like, and rename them without screwing up the relationships. Only deletion would break it. hth, /---------------------------------------------------\ Casey Duncan, Sr. Web Developer National Legal Aid and Defender Association c.duncan@nlada.org \---------------------------------------------------/
Couldn't you use the catalog for this?
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of marc lindahl
Couldn't you use the catalog for this?
Not easily. I would have to store the objects path to to make shure that i refer to the correct object. The id is not enough. And that seems kind of flimsy to me as I cannot know when the object has been moved or renamed. regards Max M Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
From: "Max M" <maxmcorp@worldonline.dk>
Not easily. I would have to store the objects path to to make shure that i refer to the correct object. The id is not enough.
Hmm.... can't you get the absolute_url of the objects of the search results?
And that seems kind of flimsy to me as I cannot know when the object has been moved or renamed.
With the catalog? Things get reindexed when you move or rename them...
* Max M <maxmcorp@worldonline.dk> [011022 20:44]:
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
What I do now is having a studentlist under each subject. But this doesn't really work because any single student can belong to any number of subjects.
So if this was an ordinary relational db it would be many to many.
So, how do YOU guys do many-to-many in Zope ?
This is what the ZCatalog is for: For example, have a property for students which is a list of subject ids. This makes it easy to list subjects by students. Now if you make this property be an index on the ZCatalog, you can easily retrieve all students by subject, too. hth seb
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of seb bacon
This is what the ZCatalog is for:
For example, have a property for students which is a list of subject ids. This makes it easy to list subjects by students. Now if you make this property be an index on the ZCatalog, you can easily retrieve all students by subject, too.
The problem with that approach is that every id mus be unique all over the site. And that is not feasible. I would also need to save information about the objects path to make shure it is the correct object. folder1/ subject1 subject2 folder2/ subject1 subject3 student1 subjects = [subject1, subject2] In this case there is no way to know which "subject1" is the right one. That I could avoid by using this organisation: subjects/ subject1 subject2 subject3 students/ student1 subjects = [subject1, subject2] Regards Max M Max M. W. Rasmussen, Denmark. New Media Director private: maxmcorp@worldonline.dk work: maxm@normik.dk ----------------------------------------------------- Shipping software is an unnatural act
Hi Max, I have a third ZClass, "Enrollment" which has two properties: student_id and class_id. Now you can write a method: getStudentIdsForClass(class_id) or getClassIdsForStudent(student_Id). With ZPatterns you can easily map these methods on to "listish" properties of the Students/Classes. -steve On Monday, October 22, 2001, at 02:44 PM, Max M wrote:
I am in the situation where I have to do what corresponds to a many-to-many relation in Zope.
I basically have two zClassses. students and subjects. There can be many subjects, and in any subject there can be any number of students.
[Steve Spicklemire]
I have a third ZClass, "Enrollment" which has two properties: student_id and class_id. Now you can write a method: getStudentIdsForClass(class_id) or getClassIdsForStudent(student_Id). With ZPatterns you can easily map these methods on to "listish" properties of the Students/Classes.
Right, a relation table. Exactly what you would do if you were using a relational database. Cheers, Tom P
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 .... -- _/ _/ _/_/_/ _/_/ Michel.Vayssade@UTC.fr Service Informatique _/ _/ _/ _/ T:33/0-3.44.23.49.24 Universite de Technologie _/ _/ _/ _/ F:33/0-3.44.23.46.77 BP 20.529 60205 Compiegne _/_/ _/ _/_/ _ mv@utc.fr __/www.utc.fr/~vayssade____ France
[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
participants (10)
-
Casey Duncan -
Joel Burton -
marc lindahl -
Max M -
Michel Vayssade -
seb bacon -
Stephan Richter -
Steve Spicklemire -
Thomas B. Passin -
Trevor Toenjes