[Zope] beginner's question: references
Michel Pelletier
michel@digicool.com
Tue, 07 Mar 2000 03:36:25 -0800
Perrin Harkins wrote:
>
> On Mon, 6 Mar 2000, Evan Simpson wrote:
> > From: Perrin Harkins <perrin@primenet.com>
> > > This is such a stupid question, but I can't seem to figure it out from
> > > the docs. How do I make an object in Zope reference another object?
> [...]
> > 2. Store the object as an attribute of the referencing object. This has to
> > be done (I think) from an External Method, since you *aren't* setting a
> > property. You do something like "self.fooref = self.path.to.other.aq_base"
> > which DTML doesn't allow.
You can do this, but you must be sure you understand that your object
now references the other object without the Zope framework's
'knowledge'. This is not a bad thing and happens all the time, but you
should be familiar with what this does to things like garbage
collection, persistent object deactivation, and circular references.
> Thanks, that sounds like what I'm after. I don't quite understand why
> this is not setting a property. Can you point me to some documentation
> that might help explain the difference?
I don't know what you were trying to do before, so I can't answer this.
> I guess putting in a little Python is no big deal, but it does break my
> ultimate goal of letting non-technical people create new classes of
> content. Is there any plan to add inter-object relationships to ZClasses?
You mean references? We've thought about this problem a little and Jim
and I discussed this over Chinese buffet once, I obviously had less of a
clue than him, but I belive the result of our discussion is that there
should be some sort of standard for one Zope object to refer to
another. The simplest way we could think of is simply storing the
path. Such as:
attribute = "../../relative/path/to/other/object"
or perhaps:
attribute = '/absolute/path/to/object'
Then when you want the object you ask Zope to resolve that path for
you. Currently you can use REQUEST.resolve_url(attribute) to do that
for you.
If you're not working on python you can simply set a string property as
the path.
This is how ZCatalog does it (actually ZCatalog uses a slightly dumber
version of this concept, don't ask). HOWEVER, the lack of any kind of
standard or support for such references in the framework has bitten
ZCatalog (and webdav) in the past, and the decisions we made will
probably come back to haunt us real soon now. You have been warned.
-Michel