'Helper method to update a foreign key in an already written
record. Will be called by the referenced item after (and only
if) it has been committed. This is only needed if the reference
could not be resolved before commit due to circular references.
@param field: the field name of the foreign key
@param value: the value of the foreign key'

def _update_reference(self, field, value):

    MTIME = current.xml.MTIME
    table = self.table
    record_id = self.id
    if ((not value) or (not table) or (not record_id) or (not self.permitted)):
        return
    if (MTIME in table.fields):
        modified_on = table[MTIME]
        modified_on_update = modified_on.update
        modified_on.update = None
    else:
        modified_on_update = None
    db = current.db
    fieldtype = str(table[field].type)
    if fieldtype.startswith('list:reference'):
        query = (table._id == record_id)
        record = db(query).select(table[field], limitby=(0, 1)).first()
        if record:
            values = record[field]
            if (value not in values):
                values.append(value)
                db((table._id == record_id)).update(**{field: values})
    else:
        db((table._id == record_id)).update(**{field: value})
    if (modified_on_update is not None):
        modified_on.update = modified_on_update
