I am working on the OpenAcaDept distribution. I have enabled entity translation for users, and translated one user into different language. This user is duplicated in view four times. Distinct is enabled.

Generated query is:

SELECT DISTINCT users.uid AS uid, users.picture AS users_picture, users.name AS users_name, users.mail AS users_mail, field_data_field_profile_last_name.field_profile_last_name_value AS field_data_field_profile_last_name_field_profile_last_name_v, field_data_field_profile_first_name.field_profile_first_name_value AS field_data_field_profile_first_name_field_profile_first_name, 'user' AS field_data_field_profile_first_name_user_entity_type, 'user' AS field_data_field_profile_middle_name_user_entity_type, 'user' AS field_data_field_profile_last_name_user_entity_type, 'user' AS field_data_field_profile_academic_degree_user_entity_type, 'user' AS field_data_field_student_speciality_user_entity_type, 'user' AS field_data_field_admission_year_user_entity_type
FROM 
{users} users
LEFT JOIN {field_data_field_student_speciality} field_data_field_student_speciality ON users.uid = field_data_field_student_speciality.entity_id AND (field_data_field_student_speciality.entity_type = 'user' AND field_data_field_student_speciality.deleted = '0')
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_field_data_field_student_speciality ON field_data_field_student_speciality.field_student_speciality_tid = taxonomy_term_data_field_data_field_student_speciality.tid
LEFT JOIN {field_data_field_profile_academic_degree} field_data_field_profile_academic_degree ON users.uid = field_data_field_profile_academic_degree.entity_id AND (field_data_field_profile_academic_degree.entity_type = 'user' AND field_data_field_profile_academic_degree.deleted = '0')
LEFT JOIN {taxonomy_term_data} taxonomy_term_data_field_data_field_profile_academic_degree ON field_data_field_profile_academic_degree.field_profile_academic_degree_tid = taxonomy_term_data_field_data_field_profile_academic_degree.tid
INNER JOIN {users_roles} users_roles ON users.uid = users_roles.uid
LEFT JOIN {field_data_field_profile_last_name} field_data_field_profile_last_name ON users.uid = field_data_field_profile_last_name.entity_id AND (field_data_field_profile_last_name.entity_type = 'user' AND field_data_field_profile_last_name.deleted = '0')
LEFT JOIN {field_data_field_profile_first_name} field_data_field_profile_first_name ON users.uid = field_data_field_profile_first_name.entity_id AND (field_data_field_profile_first_name.entity_type = 'user' AND field_data_field_profile_first_name.deleted = '0')
WHERE (( (users_roles.rid = '3') ))
ORDER BY field_data_field_profile_last_name_field_profile_last_name_v ASC, field_data_field_profile_first_name_field_profile_first_name ASC
LIMIT 30 OFFSET 0

Comments

dealancer’s picture

Version: 7.x-3.0-rc1 » 7.x-3.0-rc3

The same happens with views 7.x-3.0-rc3.

dealancer’s picture

I have simplified query while issue can be reproduced. I select uid, name and make sorting by name. Here is a query generated:

SELECT DISTINCT users.uid AS uid, field_data_field_profile_first_name.field_profile_first_name_value AS field_data_field_profile_first_name_field_profile_first_name, 'user' AS field_data_field_profile_first_name_user_entity_type
FROM 
{users} users
LEFT JOIN {field_data_field_profile_first_name} field_data_field_profile_first_name ON users.uid = field_data_field_profile_first_name.entity_id AND (field_data_field_profile_first_name.entity_type = 'user' AND field_data_field_profile_first_name.deleted = '0')
ORDER BY field_data_field_profile_first_name_field_profile_first_name ASC
LIMIT 30 OFFSET 0

If I remove sorting by name I have following which shows results without duplicates:

SELECT DISTINCT users.uid AS uid, 'user' AS field_data_field_profile_first_name_user_entity_type
FROM 
{users} users
LIMIT 30 OFFSET 0
dealancer’s picture

Project: Views (for Drupal 7) » Entity Translation
Version: 7.x-3.0-rc3 » 7.x-1.0-alpha1

When I manually run first query in previous comment, I've got result set with names in both languages. There is no condition in query to select fields of proper language.

In Query settings Field Language have value of Current user's language and following checkbox is set: "When needed, add the field language condition to the query is".

Looks like it not Views, but Entity Translation issue, so updating Project for this issue.

dealancer’s picture

Priority: Normal » Major

Does anyone can reproduce this?

good_man’s picture

Views queries exports are not enough, steps to reproduce is better, that's how it can be solved.

RuiMendes’s picture

Hi this is happening also to me.

Here is what I've got:

  • multilingual user field called Display Name
  • a view that displays all the users sorted by the Display Name

With this sort there are duplicated items, but if I sort by the system username, there is no problem.

This happens every time I try to sort a view by a translated field.

Thanks.

plach’s picture

dxvargas’s picture

Component: Miscellaneous » Base system

I would leave this issue open, because it is an important and well defined part of the other mentioned in #7.
This still happens in version "7.x-3.5", issue's version should be updated.
Also, I would change the title for this issue, to "Duplicates in views using entity translation when sorting results".

When the sort field is added (Display Name in this case), a LEFT JOIN is added to the query, but with no filter by language, so duplicates appear.

One solution is to override the "views_handler_sort" to add this filter (that's what we did).

The ideal solution would be Views module to use another handler for sorting fields, which would take into consideration the language when making the LEFT JOIN.

So, I would finally change this Issue back to the Views project.

aleck_wi’s picture

subscribe, this issue is existing for me too. I have removed a sort field for bypass

rattusrattus’s picture

This is also and issue for me. Could you give some more information about overriding the view_hander_sort

dustinleblanc’s picture

Also having this exact same issue. I am displaying a list of users by name on a multi-lingual site and it is duplicating entries if sort by name is turned on.

tunic’s picture

Title: Duplicates in views if entity translated using entity translation » Duplicates in views using entity translation when sorting results
Version: 7.x-1.0-alpha1 » 7.x-1.0-beta3
Status: Closed (duplicate) » Active

I'm reopening this bug because the problem of duplicated items appears when using a sort criteria (so it's not a duplicate issue). Using the title suggested by hiphip.

I'm not sure if this shoud go to Views instead of entity translation.

As a workaround distinct results can be enabled inthe view, but with a performance penalty.

plach’s picture

Status: Active » Closed (duplicate)

I think you just need to add a field language filter. This is a duplicate and it should not reopened no matter what, see #7.

tunic’s picture

If I understand it the solution is to add a language filter for every selected field. So, if my view has 3 content fields, say title, field1 and field2, I have to add 3 filters, each one with language filter on each added field.

That works for translated fields, but if I add nid field and sort by nid I've duplicated results. As long as nid is not translatable I can't add a language filter for that field. I can add a Content: language filter but I see duplicated results anyway.

I'm testing this in a full site so I'll wait to test it in a fresh install and post and exported feature with a test case.

plach’s picture

Duplicates should be displayed only when filtering or sorting translatable fields: untranslatable fields should not affect the result cardinality, moreover nid is stored in the base table hence it does not imply a join, so I cannot imagin how it would produce duplicates.

Adirael’s picture

Is there a way to avoid duplicates by filtering the field language but also having a fallback?

le72’s picture

Issue still exists :-(

pierregermain’s picture

I have the same issue. Seems like deleting the sort and putting it back in makes the view work correctly.

original_ZX81’s picture

Just wanted to leave a note here. I was able to resolve this by finding which Sort field was causing the duplicates. Then under Filters (not sort) I added the language filter specific to the sort field that was causing duplicates. It will look something like this when you search for it:

Content: YourFieldName (field_your_field_name:language)
Language - Appears in: node:your_node_type.

vensires’s picture

+1 on solution proposed by digitalphasedesign at #19! It may not fix the issue but it definitely produces a correct workaround.

stred’s picture

thanks #19!
to make things more clear imagine you want to display sorted taxonomy terms

in Fields add
Entity translation: Name

in Filter criteria
Taxonomy term: Name:language (= Current user's language)

and in Sort criteria
Taxonomy term: Name (asc)

chris mcgrath’s picture

Not sure if others are still having issues. In Drupal 8 I was getting duplicate nodes on Views until adding the Default translation filter. That fixed things.

knalstaaf’s picture

In my case a Weight field as a sorting criterion was causing duplicate results in a Views display. The weight field itself has translation enabled to it (but is not as such available in the sorting criteria).

The solution is to add the same translated Weight field as a filter criterion (user's current language), so along the lines of what's proposed in #21.

VBN’s picture

Had it also in latest 8.2.4 core.
Multiple language, creating a View with users.
Everything double...

Adding the Filter criteria: Default Translation (is equal to: True) fixed the problem.
Thank you Chris McGrath

naamaan’s picture

Hi,
I'm stuck in the same problem for several days!!
Running Drupal 7.56 and having a view (7.x-3.18) of content type which contains two translated taxonomy terms using entity translation (7.x-1.0-beta7).

I'd tried almost all the solutions in this forum and other similar ones but in-vain, when sorting the view using any of the translated taxonomy terms the results are duplicated!

I was trying the #21 solution; but in the SORT CRITERIA I couldn't find any `Taxonomy term:` as mentioned there, is there any reason for this? or it's a missing settings somewhere?

Regards,

pradslion’s picture

Hi There,

Try enabling "DISTINCT" feature for your view. In the advance settings, lookout for "Query" settings. Within that, just check the 2nd checkbox (i.e "Distinct") and save the settings. Bingo, duplicate entries will get vanished.

Regards,
Pradslion

tunic’s picture

@Pradslion Using 'distinct' option is a workaround, but usually there's a performance penalty.