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

Patrick Hampton animusmontus at netzero.com
Mon Jun 7 22:16:28 EDT 2004


import ZODB
import Persistence
import BTrees

strg = ZODB.FileStorage.FileStorage("/tmp/temp.fs")
db = ZODB.DB(strg)
conn = db.open()
root = conn.root()

root['games'] = BTrees.OOBTree.OOBTree()
root['players'] = BTrees.OOBTree.OOBTree()

class Game(Persistence.Persistent):
    def __init__(self):
        self.name = ''
        self.gamemaster = None
        self.players = []

class Player(Persistence.Persistent):
    def __init__(self):
        self.name = ''
        self.address = ['', '', '', '']
        self.phone = ''
        self.email = ''
        self.password = ''

player = Player()
player.name = 'Player 1'

game = Game()
game.name = 'Game 1'
game.gamemaster = player

root['players'][player.name] = player
root['games'][game.name] = game
get_transaction().commit()

---

When the commit happens does the player object get written into the games
database with the game object or does a reference get written into the game
object?

----- Original Message ----- 
From: "Tim Peters" <tim at zope.com>
To: "'Patrick Hampton'" <animusmontus at netzero.com>
Sent: Sunday, June 06, 2004 10:59 PM
Subject: RE: [ZODB-Dev] Storing Persistent Objects with Persistent Objects
as attributes of the Parent PO


> [Patrick Hampton]
> > One I was talking about instances of a persistent class. I understand
> > under simple one level objects stored to a branch off of root that if it
> > has not changed it won't be written to the storage.
> >
> > (I believe you have already answered my question, but I just want to be
> > sure...)
> >
> > What I want to know is not whether it gets written to the database or
> > not, rather where in the database it gets written to? If O has already
> > been written to another branch off of the root, will committing P to
it's
> > own branch write O somewhere under P's branch or will it just write O
> > where it's already been assigned and just make a reference to it in P's
> > storage.
>
> Sorry, I don't understand the question.  ZODB has no concept of
"branches",
> and I don't know what you *might* mean by that.
>
> Please give a specific example (the closer it is to actual code, the less
> blind guessing is needed), and please too keep it on the mailing list
> (someone else may have a better feel for your lingo than I do, and I can't
> promise to make time to reply regardless).  Thanks!
>
>




More information about the ZODB-Dev mailing list