Content listing shows duplicate content for articles with more than one author (due to relationship with people reference that allows filtering by author) #236

Closed
opened 2023-06-14 16:18:22 +00:00 by mlncn · 7 comments
mlncn commented 2023-06-14 16:18:22 +00:00 (Migrated from gitlab.com)

Easiest/best (?) solution from the long thread on Drupal.org about this is the third comment posted on that issue:

use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;

/**
 * Implements hook_views_query_alter().
 */

function custommodule_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
 if ($view->id() == 'VIEW_ID' && $view->getDisplay()->display['id'] == 'DISPLAY_ID') {
    $query->addField('', 'nid', '', ['function' => 'groupby']);
    $query->addGroupBy('nid');
    }
}

OK that's the cleanest/quickest, best of course would be a core patch and second-best is upgrading the Views Distinct module but all the directions those are going look so messy.

Alternatively maybe possible to filter without doing the relationship the same way? Or just to do the grouping in the view…

Reference (searched for "drupal views prevent duplicate content with relationship")

Maybe add any reliable workaround found to documentation here: https://www.drupal.org/docs/8/core/modules/views/add-a-relationship-to-a-view

Easiest/best (?) solution from the [long thread on Drupal.org about this](https://www.drupal.org/project/drupal/issues/2993688) is the third comment posted on that issue: ```php use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\query\QueryPluginBase; /** * Implements hook_views_query_alter(). */ function custommodule_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { if ($view->id() == 'VIEW_ID' && $view->getDisplay()->display['id'] == 'DISPLAY_ID') { $query->addField('', 'nid', '', ['function' => 'groupby']); $query->addGroupBy('nid'); } } ``` OK that's the cleanest/quickest, best of course would be a core patch and second-best is [upgrading the Views Distinct module](https://www.drupal.org/project/views_distinct/issues/2609938) but all the directions those are going look so messy. Alternatively maybe possible to filter without doing the relationship the same way? Or just to do the grouping in the view… #### Reference (searched for "drupal views prevent duplicate content with relationship") - [Duplicate Flagged Nodes in View [#2922066] | Drupal.org](https://www.drupal.org/project/flag/issues/2922066) - [Duplicate nodes when using Views relationships [#2941499] | Drupal.org](https://www.drupal.org/project/paragraphs/issues/2941499) - [9 - How to prevend duplicates of content in a view? - Drupal Answers](https://drupal.stackexchange.com/questions/308492/how-to-prevend-duplicates-of-content-in-a-view) Maybe add any reliable workaround found to documentation here: https://www.drupal.org/docs/8/core/modules/views/add-a-relationship-to-a-view
mlncn commented 2023-06-14 16:18:22 +00:00 (Migrated from gitlab.com)

assigned to @mlncn

assigned to @mlncn
mlncn commented 2023-06-14 16:22:52 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
mlncn commented 2023-06-14 16:49:14 +00:00 (Migrated from gitlab.com)

mentioned in commit 5052c4745e

mentioned in commit 5052c4745e6488e0862de39b74b6f111e5a0518d
mlncn commented 2023-06-14 16:59:03 +00:00 (Migrated from gitlab.com)

Under Advanced settings, where it says Aggregation: No select it and toggle it to use aggregation. All done no further configuration needed for it to start cleaning up the extra rows due to the relationship to multiple referenced entities.

(Screenshots for turning this into a blog post and/or documentation.)

Screenshot_2023-06-14_at_12-52-12_Content__Content__Agaric

Screenshot_2023-06-14_at_12-51-47_Content__Content__Agaric

Screenshot_2023-06-14_at_12-50-50_Content__Content__Agaric

Under Advanced settings, where it says Aggregation: No select it and toggle it to use aggregation. All done no further configuration needed for it to start cleaning up the extra rows due to the relationship to multiple referenced entities. (Screenshots for turning this into a blog post and/or documentation.) ![Screenshot_2023-06-14_at_12-52-12_Content__Content__Agaric](/uploads/7b12e96957c0c25835e31bf86e0d293c/Screenshot_2023-06-14_at_12-52-12_Content__Content__Agaric.png) ![Screenshot_2023-06-14_at_12-51-47_Content__Content__Agaric](/uploads/97557b351e30ecf6d2943856cdb560e7/Screenshot_2023-06-14_at_12-51-47_Content__Content__Agaric.png) ![Screenshot_2023-06-14_at_12-50-50_Content__Content__Agaric](/uploads/c36564e33d271b4c907a1b2594de9bc3/Screenshot_2023-06-14_at_12-50-50_Content__Content__Agaric.png)
mlncn commented 2023-06-14 16:59:54 +00:00 (Migrated from gitlab.com)

mentioned in commit b4c8f366b4

mentioned in commit b4c8f366b4e84fc77bc69af43fdfa21c5901caf2
mlncn commented 2023-06-14 17:08:24 +00:00 (Migrated from gitlab.com)

assigned to @FreeScholar

assigned to @FreeScholar
lelkneralfaro commented 2023-07-03 17:37:40 +00:00 (Migrated from gitlab.com)

@MegaKeegMan and @lelkneralfaro verified.

@MegaKeegMan and @lelkneralfaro verified.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: agaric/agaric-coop#236
No description provided.