Bugfix for self-relationships (Closes #142)