We have a person object, the Person object has a child object Email. the Email object is an editable Child.
When we load the Person object for someone that does not have an email, we get an empty object. isNew-=false.
When we set the Email address and save the person, the email goes to ChildUpdate, which fails because of missing key's to teh stored procedure.
Shouldn't the empty object be considered new?
No, since you probably created the Email as part of a fetch (and its Child_Fetch runs), MarkOld is called, which means it exists in the db.
You'll need some logic in your Person's Fetch routine that creates a new Email, and its state will be correct.
The only thing to watch for is that this means your Person will always be dirty (new objects are dirty by definition). So you'll either have to live with it, or call MarkClean after you create the new Email object (likely in the Email object's Create factory method, not in the Child_Create).
Another possibility is to "lazy load" the child object. So, you don't instantiate it until someone references the property, and it will properly be New and not get marked old. The trade off is an additional round trip to the server to fetch the address, so this works well in some cases (when the email address is shown only on a form or property page somewhere) and very poorly in others (you want to show the email address in a grid with a list of the employees).
Copyright (c) Marimer LLC