<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_related_object(self, related_model, related_id_field, obj):
 """Get a related object :param Model related_model: an sqlalchemy model :param str related_id_field: the identifier field of the related model :param DeclarativeMeta obj: the sqlalchemy object to retrieve related objects from :return DeclarativeMeta: a related object """

        try:
            related_object = self.session.query(related_model)\
                                         .filter(getattr(related_model, related_id_field) == obj['id'])\
                                         .one()
        except NoResultFound:
            raise RelatedObjectNotFound("{}.{}: {} not found".format(related_model.__name__,
                                                                     related_id_field,
                                                                     obj['id']))

        return related_object