[ZODB-Dev] Storing Persistent Objects with Persistent Objects as attributes of the Parent PO

Tim Peters tim at zope.com
Sun Jun 6 21:20:12 EDT 2004


[Patrick Hampton]
> Lets say I have a class for game data and a class for player data. Both
> the classes are stored off the root in "games" and "players". The game
> class also has an attribute which will be set to a player class.
>
> Question: When you commit a transaction on the game class, will it save
> the attribute set to the player class as a reference to the player class
> which is stored in "players" or will it write out that player class again
> in the game class object.

Sorry, I'm not clear on whether you're asking about classes, or about
instances of classes.  Stuff like "When you commit a transaction on the game
class" just doesn't make sense to me.

If P is a persistent object, and O is a persistent object, and you do

     P.whatever = O
     get_transaction().commit()

and O was not modified during this transaction, then O itself is not written
to the database again.  If O was also modified during this transaction, then
O will be written to the database again.  In either case P.whatever is a
reference to O.

If you're actually asking about classes, classes are not persistent objects.
If an attribute of a persistent object is bound to a class object, the class
object is represented in the database essentially by means of its name (a
string).  When an attempt to load the class from the database is made, the
stored name is used to drive a Python import (so you always get the current
implementation of the class, even if that's different from the
implementation that existed when the name of the class was stored in the
database).




More information about the ZODB-Dev mailing list