Protect against relation loops (fixes #2072)