'Return the primaryjoin condition suitable for the
"reverse" direction.
If the primaryjoin was delivered here with pre-existing
"remote" annotations, the local/remote annotations
are reversed.  Otherwise, the local/remote annotations
are removed.'

@util.memoized_property
def primaryjoin_reverse_remote(self):

    if self._has_remote_annotations:
        def replace(element):
            if ('remote' in element._annotations):
                v = element._annotations.copy()
                del v['remote']
                v['local'] = True
                return element._with_annotations(v)
            elif ('local' in element._annotations):
                v = element._annotations.copy()
                del v['local']
                v['remote'] = True
                return element._with_annotations(v)
        return visitors.replacement_traverse(self.primaryjoin, {}, replace)
    elif self._has_foreign_annotations:
        return _deep_deannotate(self.primaryjoin, values=('local', 'remote'))
    else:
        return _deep_deannotate(self.primaryjoin)
