[Zope-dev] relations in objects

Paul Winkler pw_lists at slinkp.com
Fri Oct 10 02:54:38 EDT 2003


On Thu, Oct 09, 2003 at 08:46:24PM -0700, Jason Corbett wrote:
> Thanks for your reply.  I've actually been thinking in
> an object oriented form for a while.  I've looked at
> implimenting this project in Java using either
> prevailance or a object persistence model that mapped
> to a RDBMS.  I like the idea of zope, so maybe I
> should clarify my question:
> 
> How does an object in zope know where it sits in the
> hirearchy,

The only unique identifier that zope provides is
the containment path. An object can tell you its containment
path by doing foo.absolute_url(1) or foo.getPhysicalPath()
depending on what form you  want the output in.

> and how does it reach other objects. 

By path. Zope provides a number of ways to express paths in
python:

foo["some"]["path"]    # does NOT use acquisition, only containment
foo.some.path          # uses acquisition
getattr(foo.some, "path") # uses acquisition

foo.unrestrictedTraverse("/some/path/from/zope/root")
foo.unrestrictedTraverse("some/path/relative/to/foo")
(see also restrictedTraverse)

Note that storing a direct reference may be dangerous e.g. 
you might not have the object you are expecting - in fact it's
very likely that you get an acquisition wrapper which may change
at any time.  On the other hand, storing paths is problematic if 
you want to be able to move or rename an object and still keep 
references to it elsewhere.  Hence, look at mxmRelations which 
helps with this.

-- 

Paul Winkler
http://www.slinkp.com



More information about the Zope-Dev mailing list