def ref(self, orm_classpath, cls_pk=None):
<EOL>orm_module, orm_class = get_objects(orm_classpath)<EOL><INDENT>if orm_classpath.startswith("<STR_LIT:.>"):<EOL><INDENT>if self.orm_class:<EOL><INDENT>try:<EOL><INDENT>orm_module, orm_class = get_objects(<EOL>orm_classpath,<EOL>self.orm_class.__module__<EOL>)<EOL><DEDENT>except ImportError:<EOL><INDENT>parents = inspect.getmro(self.orm_class)<EOL>if parents:<EOL><INDENT>for pc in parents[<NUM_LIT:1>:-<NUM_LIT:1>]:<EOL><INDENT>try:<EOL><INDENT>orm_module, orm_class = get_objects(<EOL>orm_classpath,<EOL>pc.__module__<EOL>)<EOL><DEDENT>except ImportError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if not orm_module or not orm_class:<EOL><INDENT>raise ImportError(<EOL>"<STR_LIT>".format(<EOL>self.orm_class.__module__<EOL>)<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>raise ImportError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>orm_module, orm_class = get_objects(orm_classpath)<EOL><DEDENT>if isinstance(orm_classpath, basestring):<EOL><INDENT>orm_module, orm_class = get_objects(orm_classpath)<EOL><DEDENT>else:<EOL><INDENT>orm_module, orm_class = get_objects(orm_classpath[<NUM_LIT:0>], orm_classpath[<NUM_LIT:1>])<EOL><DEDENT><DEDENT>q = orm_class.query<EOL>if cls_pk:<EOL><INDENT>found = False<EOL>for fn, f in orm_class.schema.fields.items():<EOL><INDENT>cls_ref_s = f.schema<EOL>if cls_ref_s and self.schema == cls_ref_s:<EOL><INDENT>q.is_field(fn, cls_pk)<EOL>found = True<EOL>break<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>raise ValueError("<STR_LIT>".format(<EOL>self.orm_class.table_name,<EOL>orm_class.table_name,<EOL>))<EOL><DEDENT><DEDENT>return q<EOL>
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()