'Update the shared fields in data in all super-entity rows linked
with this record.
@param table: the table
@param record: a record, record ID or a query
@param data: the field/value pairs to update'

def update_shared_fields(self, table, record, **data):

    db = current.db
    s3db = current.s3db
    super_entities = s3db.get_config(table, 'super_entity')
    if (not super_entities):
        return
    if (not isinstance(super_entities, (list, tuple))):
        super_entities = [super_entities]
    tables = dict()
    load = s3db.table
    super_key = s3db.super_key
    for se in super_entities:
        supertable = load(se)
        if ((not supertable) or (not any([(f in supertable.fields) for f in data]))):
            continue
        tables[super_key(supertable)] = supertable
    if ((not isinstance(record, (Row, dict))) or any([(f not in record) for f in tables])):
        if isinstance(record, Query):
            query = record
            limitby = None
        elif isinstance(record, (Row, dict)):
            query = (table._id == record[table._id.name])
            limitby = (0, 1)
        else:
            query = (table._id == record)
            limitby = (0, 1)
        fields = [table[f] for f in tables]
        records = db(query).select(limitby=limitby, *fields)
    else:
        records = [record]
    if (not records):
        return
    for record in records:
        for skey in tables:
            supertable = tables[skey]
            if (skey in record):
                query = (supertable[skey] == record[skey])
            else:
                continue
            updates = dict(((f, data[f]) for f in data if (f in supertable.fields)))
            if (not updates):
                continue
            db(query).update(**updates)
