Relation query improvements (handle many relations between two entities, break loops, limit max level)