fix: Avoid joining tables to fix the distinct value query (#7965)

DISTINCT query with custom attributes return an error. To avoid the error, this PR refactors the query to include tags only when it is required.

Fixes #7931
Fixes #7836

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S
2023-09-22 19:48:56 -07:00
committed by GitHub
parent dd0930d75e
commit ff915dd2ea
4 changed files with 94 additions and 30 deletions

View File

@@ -35,7 +35,7 @@ class Contacts::FilterService < FilterService
" (contacts.#{attribute_key})::#{current_filter['data_type']} #{filter_operator_value}#{current_filter['data_type']} #{query_operator} "
when 'standard'
if attribute_key == 'labels'
" tags.id #{filter_operator_value} #{query_operator} "
tag_filter_query('Contact', 'contacts', query_hash, current_index)
else
" LOWER(contacts.#{attribute_key}) #{filter_operator_value} #{query_operator} "
end
@@ -54,7 +54,7 @@ class Contacts::FilterService < FilterService
end
def base_relation
Current.account.contacts.distinct(:id).left_outer_joins(:labels)
Current.account.contacts
end
private