Rethinking the structure again
Posted by mholmes on 03 Jun 2009 in Activity log
I've started rewriting the classes from scratch, on the basis that the capability to use and track unique ids for every form element while maintaining the ability to edit multiple instances of records from the same table at the same time, requires that uniqueness be built in from the bottom up. This gradually led me to a point where I've realized that:
- Every MdhRecord object needs a unique suffix which can be used to distinguish HTML elements it creates.
- A "linked table" that is associated with it is actually just another kind of field. I need to create a field type which wraps an instance of MdhRecordList.
- While MdhRecord objects should create their own $suffix attribute when they're created, to append ot ids, when the new kind of field creates a record list, which in turn creates records, it should intervene to prepend its own parent's suffix to the auto-created suffix, so the embedded record does have a unique id, but that unique id sorts with the ids of its parent object.
- An object can detect whether it's nested by checking its suffix to see if the strrpos of a period is 0; if it's not, then the object is embedded.
- If the object is embedded, its Edit and Save JavaScript calls will just call different functions, which modify the display in the browser, but don't submit any changes.
- A record list object will similarly know whether it's embedded or not, because it will have a suffix (root record list objects will have empty suffixes). Thus the record list object, when rendering its New Record button, can decide which JavaScript function to call.
This will take a lot more rewriting, but it's definitely the way to go, because it will allow for nested object editing with robust uniqueness of id, along with the ability to edit multiple records simultaneously. That's user-friendly.