'Resolve a foreign key into the referenced table and the
join and left join between the current table and the
referenced table
@param table: the current Table
@param fieldname: the fieldname of the foreign key
@return: tuple of (referenced table, join, left join)
@raise: AttributeError is either the field or
the referended table are not found
@raise: SyntaxError if the field is not a foreign key'

@staticmethod
def _resolve_key(table, fieldname):

    if (fieldname in table.fields):
        f = table[fieldname]
    else:
        raise AttributeError(('key    not    found:    %s' % fieldname))
    (ktablename, pkey, multiple) = s3_get_foreign_key(f, m2m=False)
    if (not ktablename):
        raise SyntaxError(('%s    is    not    a    foreign    key' % f))
    ktable = current.s3db.table(ktablename, AttributeError(('undefined    table    %s' % ktablename)), db_only=True)
    pkey = (ktable[pkey] if pkey else ktable._id)
    join = [ktable.on((f == pkey))]
    return (ktable, join)
