domain: Use DISTINCT for entity queries with joins.
Merge branch 'master' into stable

* master:
  domain: Use DISTINCT for entity queries with joins.