def ensure_join(self, lm, rm, on=None):
        ctx = self._query_ctx
        for join in self._joins.get(lm, []):
            if join.dest == rm:
                return self
        return self.switch(lm).join(rm, on=on).switch(ctx)
dataset/ETHPy150Open coleifer/peewee/peewee.py/Query.ensure_join/original