'Create/update all records from the form.
@param form: the form
@param format: data format extension (for audit)
@param link: resource.link for linktable components
@param hierarchy: the data for the hierarchy link to create
@param undelete: reinstate a previously deleted record'

def accept(self, form, format=None, link=None, hierarchy=None, undelete=False):

    db = current.db
    table = self.table
    main_data = self._extract(form)
    (master_id, master_form_vars) = self._accept(self.record_id, main_data, format=format, link=link, hierarchy=hierarchy, undelete=undelete)
    if (not master_id):
        return
    else:
        main_data[table._id.name] = master_id
        self.resource.lastid = str(master_id)
    for alias in self.subtables:
        subdata = self._extract(form, alias=alias)
        if (not subdata):
            continue
        component = self.resource.components[alias]
        subtable = component.table
        pkey = component.pkey
        if ((pkey != table._id.name) and (pkey not in main_data)):
            row = db((table._id == master_id)).select(table[pkey], limitby=(0, 1)).first()
            if (not row):
                return
            main_data[pkey] = row[table[pkey]]
        if component.link:
            link = Storage(resource=component.link, master=main_data)
        else:
            link = None
            subdata[component.fkey] = main_data[pkey]
        rows = self.subrows
        if ((alias in rows) and (rows[alias] is not None)):
            subid = rows[alias][subtable._id]
        else:
            subid = None
            subdata = component.get_defaults(main_data, data=subdata)
        self._accept(subid, subdata, alias=alias, link=link, format=format)
    for item in self.components:
        if hasattr(item, 'accept'):
            item.accept(form, master_id=master_id, format=format)
    form_vars = form.vars
    form_vars[table._id.name] = master_id
    for var in master_form_vars:
        if (var not in form_vars):
            form_vars[var] = master_form_vars[var]
    return
