[Zope] Omnipresent objects?

Oliver Bleutgen myzope@gmx.net
Mon, 07 Apr 2003 21:09:22 +0200


(This is a reply to the top post, which I can't get to ATM.)

For an analogous task, where I had to realize 1:n relations, I did the 
following:

- Create a custom folderish class ("ProductsFolder") with a ZCatalog (or 
derived from zcatalog), holding - in your case - the products (which are 
also custom objects).
- Products have a tuple-like property "category_ids"
- Create a class "Category"

The instances of Category get a special random attribute "magic_id" on 
instanciation, long enough to practically guarantee uniqueness.

The products are catalog aware and register with the zcatalog in the 
folder, which stores the property category_ids in a keyword index.

Now products can be associated with a category by adding the category's 
magic_id to the property category_ids of that product. I use simply 
ZopeFind to locate all categories for the user interface of the editors, 
because this operation doesn't happen very often.

The advantage is that this should scale quite well, for added speed you 
could use a BTree for the ProductsFolder.
You also can move/create categories anywhere you want, they always will 
act the same (hold the same products) as long as they can "see" the 
ProductsFolder.

HTH,
oliver