[DB-SIG] Saving composed objects.

Heston James - Cold Beans heston.james at coldbeans.co.uk
Thu Jul 10 14:19:02 CEST 2008


Morning Chaps,

 

I'm looking for your thoughts and advice on saving composed objects to the
database using the db API. Where do you place your persistence code? For
arguments sake let's look at a simple foo/bar example.

 

We have too classes 'foo' and 'bar', and a 'foo' can have many 'bars' within
it. How would you handle reading a 'foo' record from the database and saving
it back? Making sure that when you read it, you get a list of 'bar' objects
inside it, and when saving it saves its relationships and all contained
'bar' objects back to the database?

 

Would you place the queries which save the 'foo' and its 'bars' inside the
foo object? Or abstract it out and have 'bar' know how to save itself? If
'bar' does know how to save itself, do we call the save from within 'foo' or
abstract that call out to a save_foo() method in a service of something?
Having the service loop over the bars and save them?

 

I'm really feeling a little confused about this stuff, saving composed
objects to the database is new to me.

 

Thanks guys,

 

Heston

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20080710/d20a7dbb/attachment.htm>


More information about the DB-SIG mailing list