[Zope-dev] RFC: RelationAware class for relations between objects

roche@upfrontsystems.co.za roche@upfrontsystems.co.za
Mon, 28 Apr 2003 21:48:15 +0200


* Jeremy Hylton <jeremy@zope.com> [2003-04-28 19:58]:
> The chief difference between the vapor version and the implemented
> version is that the vapor version had a single Relation object that was
> bound to both instances and the implemented version was two Relation
> descriptors that get joined together.  The latest CVS version looks like
> this:
> 
> class SoftwareProject(object):
> 
>     developers = Relation()
>     
>     def __init__(self, name):
>         self.name = name
> 
> class Developer(object):
> 
>     projects = Relation()
>     
>     def __init__(self, name):
>         self.name = name
> 
> join(many(SoftwareProject.developers),
>      many(Developer.projects))
> 
> Does this version of the API look any better?

So far I really, really like the simplicity of it.

Here are some questions i have regarding the current API:

1. How important is it that relations should be between specific class
types. Can't one get away with just saying that a relation has a given
cardinality? Why can't one relate instances of arbitrary classes to each
other. Why worry about the class type if one has to be explicit when one
relates objects? Here is an example of how a type constraint could be
problematic:

    class Organisation(object):

    class Customer(Organisation):

    class Reseller(Organisation):

    class ContactPerson(object):

        Organisation = OneRelation()

    ZopeCorp = Customer()

    pete = ContactPerson()
    pete.Organisation.add(ZopeCorp)

2. When time permits would you fill in the detail for a one2one/one2many
relation? I am interested to see if your api would allow direct
assignment to a descriptor when one object only relates to one other
object ie.

    class Developer:
    
        projects = Relation()
        team = Relation()
        
    class Team:

        developers = Relation()

    join(one(Developer.team), many(Team.developers))

    stevea = Developer("Steve Alexander")
    ateam = Team("The A Team")

    stevea.team = ateam
    assert stevea in ateam.developers

Btw, the state of the RelationDict is corrupted when one defines more
than one Relation on a class. I know we are only talking about the API
now, just thought I'd mention it.

-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za