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

        # Prevent that reference update breaks time-delayed
        # synchronization by implicitly updating "modified_on"
        if MTIME in table.fields:
            modified_on = table[MTIME]
            modified_on_update = modified_on.update
            modified_on.update = None
        else:
            modifed_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})

        # Restore modified_on.update
        if modified_on_update is not None:
            modified_on.update = modified_on_update

    # -------------------------------------------------------------------------
Helper method to update a foreign key in an already written
dataset/ETHPy150Open sahana/eden/modules/s3/s3import.py/S3ImportItem._update_reference