'Set the base location of the instance(s)
@param location: the location for the base location as Row or record ID
@return: nothing
@note: instance tables without a location_id field will be ignored'

def set_base_location(self, location=None):

    if isinstance(location, S3Trackable):
        location = location.get_base_location()
    if isinstance(location, Rows):
        location = location.first()
    if isinstance(location, Row):
        location.get('id', None)
    if ((not location) or (not str(location).isdigit())):
        return
    else:
        data = {LOCATION_ID: location}
    for r in self.records:
        if (TRACK_ID in r):
            continue
        elif (LOCATION_ID in r):
            if hasattr(r, 'update_record'):
                r.update_record(**data)
            else:
                raise SyntaxError('Cannot    relate    record    to    a    table.')
    db = current.db
    s3db = current.s3db
    track_ids = [r[TRACK_ID] for r in self.records if (TRACK_ID in r)]
    rows = db(self.table[TRACK_ID].belongs(track_ids)).select()
    tables = []
    append = tables.append
    types = set()
    seen = types.add
    for r in rows:
        instance_type = r.instance_type
        if (instance_type not in types):
            seen(instance_type)
            table = s3db[instance_type]
            if ((instance_type not in tables) and (LOCATION_ID in table.fields)):
                append(table)
            else:
                continue
    for table in tables:
        db(table[TRACK_ID].belongs(track_ids)).update(**data)
    for r in self.records:
        if (LOCATION_ID in r):
            r[LOCATION_ID] = location
    return location
