avoid id naming collisions on query statements
extract method refactoring
Merge pull request #2323 from opf/hotfix/wp_grouping_by_users

Hotfix/wp grouping by users
Merge branch 'release/4.0' into dev

Conflicts:
	app/models/query.rb
	app/models/query/results.rb
	spec/models/query/results_spec.rb