OODB Design Question

Brent Pinkney brent at zamail.co.za
Thu Jun 14 19:44:51 UTC 2007


On Thursday, 14 June 2007 20:59, Michael Gorsuch wrote:
> Hello, I'm looking to port one of my side projects to Seaside with a
> Magma back end, and need a little clarification on how Magma would
> handle one particular situation.
>
> This service is an online dream journal (http://www.dreamjournal.com),
> and has a very simple object model.  Essentially, we have a User
> model, and a Dream model.
>
> User has an attribute called 'dreams' that holds all of that user's
> dream info.  Dreams also need to be accessed by the public (if you
> mark the dream as so), therefore I was also holding all of my dreams
> in another collection (as well as with the User).  This made it easy
> to handle sorting and what not for each view.
>
> Most importantly, the Dream object inside the User's 'dream'
> collection is the same exact Dream object stored in the master dream
> collection, allowing for changes to be made and reflected across both
> areas with ease.  If a user edits a particular dream, it changes in
> both collections.
>
> So.  Finally.  The question:
>
> If I commit a User in a Magma repository, I know that all of his
> dreams will be saved with him.  But, if I commit the master dream
> collection to the repository, and retrieve it, will it still contain
> the same exact objects that the User's have, or will they merely be
> copies?  If they are copies, perhaps someone can suggest a more
> intelligent way to manage this dataset.

They are the same objects, not copies. That is the beauty of Magma.

More specifically, let:

dreams := session root at: 'dreams'.
users := session root at: 'users'.

newUser := User name name: 'bob'.
newDream := Dream new title: 'world domination'.
newUser dreams add: newDream.

session commit: [
	users add: newUser.
	dreams add: newDream ].


And then later....

dreams := session root at: 'dreams'.
users := session root at: 'users'.

world := dreams  anyOne.
bob := users anyOne.

"Heres the proof...."
world == bob dreams anyOne.



I hope this helps

brent



More information about the Magma mailing list