[ZODB-Dev] How do you handle changes to BTree key values?

Patrick K. O'Brien pobrien@orbtech.com
Mon, 8 Oct 2001 22:22:46 -0500


In Andrew Kuchling's example (http://www.amk.ca/zodb/guide/node14.html) a
user object is stored in a Btree according to its id, which is a string.
(See code below.) Can anyone explain how changes to the user.id value are
handled in an example like this? Michel Pelletier uses employee name as the
key in his example (http://www.zope.org/Documentation/Articles/ZODB1).

If these examples are the equivalent of primary keys in a relational
database, I would never use either of these values as keys. (And if you did
you would need cascading updates, at the least.) Instead, I would use a
system-generated meaningless value, which most databases now generate for
you (such as a GUID). But I don't see the need to turn object collections
into relational structures. Objects already have identity, right?

So if all I wanted was a collection of users, why would I want to use any of
the BTrees, which required a key? What does the key buy you in ZODB? Should
the key be a value that never changes? Does the key become an attribute in
other objects similar to a foreign key in a relational database? Wouldn't
you just use an object reference itself? Why am I finding this so difficult
to get my brain around? (Too many years with relational?)

Andrew's example:

# Create new User instance
newuser = User()

# Add whatever attributes you want to track
newuser.id = 'amk'
newuser.first_name = 'Andrew' ; newuser.last_name = 'Kuchling'
...

# Add object to the BTree, keyed on the ID
userdb[ newuser.id ] = newuser

# Commit the change
get_transaction().commit()


---
Patrick K. O'Brien
Orbtech (http://www.orbtech.com)
"I am, therefore I think."