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
Comment #1
dealancer commentedThe same happens with views 7.x-3.0-rc3.
Comment #2
dealancer commentedI have simplified query while issue can be reproduced. I select uid, name and make sorting by name. Here is a query generated:
If I remove sorting by name I have following which shows results without duplicates:
Comment #3
dealancer commentedWhen 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.
Comment #4
dealancer commentedDoes anyone can reproduce this?
Comment #5
good_man commentedViews queries exports are not enough, steps to reproduce is better, that's how it can be solved.
Comment #6
RuiMendes commentedHi this is happening also to me.
Here is what I've got:
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.
Comment #7
plach#1330332-15: Entity translation: Views field language filter
Comment #8
dxvargas commentedI 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.
Comment #9
aleck_wi commentedsubscribe, this issue is existing for me too. I have removed a sort field for bypass
Comment #10
rattusrattus commentedThis is also and issue for me. Could you give some more information about overriding the view_hander_sort
Comment #11
dustinleblancAlso 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.
Comment #12
tunicI'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.
Comment #13
plachI think you just need to add a field language filter. This is a duplicate and it should not reopened no matter what, see #7.
Comment #14
tunicIf 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.
Comment #15
plachDuplicates 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.
Comment #16
Adirael commentedIs there a way to avoid duplicates by filtering the field language but also having a fallback?
Comment #17
le72Issue still exists :-(
Comment #18
pierregermain commentedI have the same issue. Seems like deleting the sort and putting it back in makes the view work correctly.
Comment #19
original_ZX81 commentedJust 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.
Comment #20
vensires+1 on solution proposed by digitalphasedesign at #19! It may not fix the issue but it definitely produces a correct workaround.
Comment #21
stred commentedthanks #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)
Comment #22
chris mcgrath commentedNot 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.
Comment #23
knalstaaf commentedIn 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.
Comment #24
VBN commentedHad 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
Comment #25
naamaan commentedHi,
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,
Comment #26
pradslion commentedHi 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
Comment #27
tunic@Pradslion Using 'distinct' option is a workaround, but usually there's a performance penalty.