simple question: why does save return the object

simple question: why does save return the object

Old forum URL: forums.lhotka.net/forums/t/9748.aspx


BunnyStrider posted on Thursday, November 11, 2010

Save returns the child object.  Why?

Marjon1 replied on Thursday, November 11, 2010

There are two things to remember when saving an object, you may be sending the object over the network in which case a copy of the original is required anyway and as part of the save process you will changing the internal meta-data and possibly standard data within the object.

When you save an object, it is common to set the ID value to another value based on something coming back from the database; and the IsNew, IsDirty flags on either the root or child objects are often changed as well. Should an error occur somewhere, these values are obviously not correct anymore (because the save failed). By returning a new object, if an exception occurs you can essential pretend that nothing happened, because your object is in the exact state is was before.

RockfordLhotka replied on Thursday, November 11, 2010

Marjon is correct. There's a very good discussion of this in Chapters 1 and 2 of Expert 2008 Business Objects.

Copyright (c) Marimer LLC