<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ref(self, orm_classpath, cls_pk=None):
 """ takes a classpath to allow query-ing from another Orm class the reason why it takes string paths is to avoid infinite recursion import problems because an orm class from module A might have a ref from module B and sometimes it is handy to have module B be able to get the objects from module A that correspond to the object in module B, but you can't import module A into module B because module B already imports module A. orm_classpath -- string -- a full python class path (eg, foo.bar.Che) cls_pk -- mixed -- automatically set the where field of orm_classpath that references self.orm_class to the value in cls_pk if present return -- Query() """

        # split orm from module path
        orm_module, orm_class = get_objects(orm_classpath)
#         if orm_classpath.startswith("."):
#             # we handle relative classpaths by using the orm_class and its parents
#             # to find the relative import
#             if self.orm_class:
#                 try:
#                     orm_module, orm_class = get_objects(
#                         orm_classpath,
#                         self.orm_class.__module__
#                     )
#                 except ImportError:
#                     parents = inspect.getmro(self.orm_class)
#                     if parents:
#                         for pc in parents[1:-1]:
#                             try:
#                                 orm_module, orm_class = get_objects(
#                                     orm_classpath,
#                                     pc.__module__
#                                 )
#                             except ImportError:
#                                 pass
# 
#                         if not orm_module or not orm_class:
#                             raise ImportError(
#                                 "Unable to resolve relative ref using {}".format(
#                                     self.orm_class.__module__
#                                 )
#                             )
# 
#             else:
#                 raise ImportError("trying relative ref without orm_class")
# 
#         else:
#             orm_module, orm_class = get_objects(orm_classpath)


#         if isinstance(orm_classpath, basestring):
#             orm_module, orm_class = get_objects(orm_classpath)
#         else:
#             orm_module, orm_class = get_objects(orm_classpath[0], orm_classpath[1])

        q = orm_class.query
        if cls_pk:
            found = False
            for fn, f in orm_class.schema.fields.items():
                cls_ref_s = f.schema
                if cls_ref_s and self.schema == cls_ref_s:
                    q.is_field(fn, cls_pk)
                    found = True
                    break

            if not found:
                raise ValueError("Did not find a foreign key field for [{}] in [{}]".format(
                    self.orm_class.table_name,
                    orm_class.table_name,
                ))

        return q