<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _model_relations(ins):
 """ Get relationships info :type ins: sqlalchemy.orm.mapper.Mapper :rtype: list[SaRelationshipDoc] """

    relations = []
    for r in ins.relationships:
        # Hard times with the foreign model :)
        if isinstance(r.argument, Mapper):
            model_name = r.argument.class_.__name__
        elif hasattr(r.argument, 'arg'):
            model_name = r.argument.arg
        else:
            model_name = r.argument.__name__

        # Format
        relations.append(SaRelationshipDoc(
            key=r.key,
            doc=r.doc or '',
            model=model_name,
            pairs=map(lambda a_b_tuple: a_b_tuple[0].key if a_b_tuple[0].key == a_b_tuple[1].key else '{}={}'.format(a_b_tuple[0].key, a_b_tuple[1].key), r.local_remote_pairs),
            uselist=r.uselist
        ))
    return relations