[Zope] unique ID of object
kapil thangavelu
k_vertigo@yahoo.com
Thu, 6 Sep 2001 16:41:02 -0700
On Thursday 06 September 2001 10:23 pm, Tom Cameron wrote:
> I need to be able to uniquely identify a zope object by another way other
> than its context and id.
>
> I want to be able to create an object and then identify that object again
> even if it has been moved in the zope tree.
>
> I assume that each zope object must have some totally unique id that I can
> call somehow.
>
> I could write a routine that generates random ids that would be almost
> unique, but I am wondering if Zope has such a feature already built in
> somewhere.
>
> Tom
the standard zope way of doing this type of thing is to use
obj.getPhysicalPath() which returns a set that basically identifies your
object uniquely from the root of zope's object heirarchy. this would be the
best way. you can reconstruct an object from a reference with
restrictedTraverse. if you need to store the reference its probably best to
use string.join(obj.getPhysicalPath, '/') and store the resulting string
reference. obviously this won't survive the object moving, so it doesn't fit
the bill.
another ways that is laced with danger are using the zodb's oid which is not
guaranteed to be unique across dbs (think import/export) and is only
accessible via python...
you could also just set the referenced object as an attribute of the object
and let python do the reference counting for you, which would require using
fs python methinks.
if you need to do this from all ttw code, you could have a unique id on the
object you generated which is subclassed from catalog aware and then ask the
catalog to reconstruct your reference to the object when you need it.
hth
kapil