Improved getInverseRelation method