Working version. Detects relation loop and multiple same type parents.