diff --git a/relation/README.txt b/relation/README.txt index 0a9d48f..be4ad49 100644 --- a/relation/README.txt +++ b/relation/README.txt @@ -1,6 +1,8 @@ Yet Another Relations (Reference) Engine... =========================================== + ($Id$) + >>> from zope.app.testing.placelesssetup import setUp >>> setUp() @@ -122,19 +124,31 @@ working with events). >>> from zope.app import zapi >>> relations = zapi.getUtility(IRelationsRegistry) -In real life the indexes needed will be set up manually after object creation -or via subscription to IObjectCreatedEvent - here we have to do this -explicitly: +In real life the indexes needed will be set up via subscription to +IObjectCreatedEvent - here we have to do this explicitly: >>> relations.setupIndexes() In order to register relations the objects that are referenced have to be registered with an IntIds (unique ids) utility, so we have to set up such -an utility (using a stub/dummy implementation for testing purposes): +an utility (using a stub/dummy implementation for testing purposes) and +register the objects with it (in real life this is done automatically +when we add an object to a container): >>> from cybertools.relation.tests import IntIdsStub >>> from zope.app.intid.interfaces import IIntIds >>> ztapi.provideUtility(IIntIds, IntIdsStub()) + >>> intids = zapi.getUtility(IIntIds) + >>> intids.register(clark) + 0 + >>> intids.register(kirk) + 1 + >>> intids.register(audrey) + 2 + >>> intids.register(washington) + 3 + >>> intids.register(newyork) + 4 We also have to provide an adapter for the Relation objects that provides the attributes needed for indexing: diff --git a/relation/__init__.py b/relation/__init__.py index 73fc03d..5ac8c4b 100644 --- a/relation/__init__.py +++ b/relation/__init__.py @@ -27,10 +27,19 @@ $Id$ from persistent import Persistent from zope.interface import implements -from interfaces import IDyadicRelation, ITriadicRelation +from interfaces import IPredicate +from interfaces import IRelation, IDyadicRelation, ITriadicRelation + +class Relation(Persistent): + + implements(IPredicate, IRelation) + + @classmethod + def getPredicateName(cls): + return '%s.%s' % (cls.__module__, cls.__name__) -class DyadicRelation(Persistent): +class DyadicRelation(Relation): implements(IDyadicRelation) @@ -39,7 +48,7 @@ class DyadicRelation(Persistent): self.second = second -class TriadicRelation(Persistent): +class TriadicRelation(Relation): implements(ITriadicRelation) diff --git a/relation/configure.zcml b/relation/configure.zcml index fb2d37c..5a43d7c 100644 --- a/relation/configure.zcml +++ b/relation/configure.zcml @@ -63,7 +63,7 @@ />