[Zope3-Users] how to model a 1-to-1 relation

Hermann Himmelbauer dusty at qwer.tk
Fri Jan 11 09:21:07 EST 2008


Am Donnerstag, 10. Januar 2008 23:00 schrieb john saponara:
> I want to allow the user to create car and driver objects in a
> limoService container.  Car objects will stand alone, but each driver
> object should contain a car object by reference (not by value) and the
> driver add form should allow the user to choose which car the new driver
> object will have.  Should IDriver's car attribute be a schema.Object or
> a schema.Choice?

That's an interesting question, as I currently have a similar problem. It 
seems that if you store one object mulitple times in the ZODB, it does not 
duplicated it but stores only references. I tested that, however, I'm unsure 
if ZODB can really handle this in all situations.

If this proves to work, things are quite easy, as one can do things like that:

class Driver(BTreeContainer):
   """ A BTreeContainer for Drivers"

# A car is owned by two drivers:

driver1 = Driver()
driver2 = Driver()
mycar = Car()

driver1['mycar'] = mycar
driver2['mycar'] = mycar

Another issue I still have to sort out are permissions for this case, e.g. 
driver1 and driver2 may set attributes, but driver3 who does not own the car, 
may not. One way would perhaps be to permit a driver modification of all 
objects in his driver-container.

Best Regards,
Hermann

-- 
hermann at qwer.tk
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7


More information about the Zope3-users mailing list