'Save this hierarchy in s3_hierarchy'

def save(self):

    if (not self.config):
        return
    tablename = self.tablename
    theset = self.theset
    if (not self.__status('dbupdate')):
        return
    nodes_dict = dict()
    for (node_id, node) in theset.items():
        nodes_dict[node_id] = {'p': node['p'], 'c': node['c'], 's': (list(node['s']) if node['s'] else [])}
    data = {'tablename': tablename, 'dirty': False, 'hierarchy': {'nodes': nodes_dict}}
    htable = current.s3db.s3_hierarchy
    query = (htable.tablename == tablename)
    row = current.db(query).select(htable.id, limitby=(0, 1)).first()
    if row:
        row.update_record(**data)
    else:
        htable.insert(**data)
    self.__status(dirty=False, dbupdate=None, dbstatus=True)
    return
