Fix for circular references in n-n relations + add tests