Tests for M2M to self relationships, and loop avoidance