Drupal Views Duplicate Values ​​Returned Using a Relationship

I have a problem with submissions. I have an idea, and I give him the term taxonomy by name. Then I have to do with the related node. For my output fields, I return the associated name and the associated Body. However, I have duplicates in my results. I became different from yes, but I believe that this works on return nodes, not node. Any ideas how I can remove duplicates?

Update

Below is the query when I get only the header

SELECT DISTINCT(node.nid) AS nid, node_node_data_field_wine_company.title AS node_node_data_field_wine_company_title, node_node_data_field_wine_company.nid AS node_node_data_field_wine_company_nid FROM node node LEFT JOIN content_type_wine node_data_field_wine_company ON node.vid = node_data_field_wine_company.vid INNER JOIN node node_node_data_field_wine_company ON node_data_field_wine_company.field_wine_company_nid = node_node_data_field_wine_company.nid LEFT JOIN term_node term_node ON node.vid = term_node.vid INNER JOIN term_data term_data ON term_node.tid = term_data.tid WHERE term_data.name = 'test' GROUP BY nid 

It looks like I should group by node_node_data_field_wine_company_nid or select different values ​​from it. Any ideas?

Update

This may not be possible if you are using Normal vies. Below is my setup.

I have a taxonomy called "Region." The scope applies to a custom content type called Wine. The Wine content type has a node reference field for the node company type. A company is a common type of node.

I have a list of all my regions. By clicking on an area, I will pass it as an argument to the presentation (name of terms). From this region I want to return all the companies in this region.

To get this, I need to get all the Wine items that have this region. With all the wines with the region, I need to get a unique node link. Then I will return it.

In one direction, this will be the provision of each company in the region (s) to compile a list. However, I would prefer it to be designed automatically from the wine type.

Any ideas?

+4
source share
1 answer

Your analysis seems correct in the sense that the distinguishing features relate to the “original” nodes, and not to the corresponding ones. Thus, you can try to "cancel" your view design, starting from now "connected" nodes, adding relation to now "original" nodes and filtering the results on the conditions of these. The last thing I’m not sure about is that I don’t know whether it is possible to apply a terminal filter on nodes drawn through relationships, but it might be worth a try.

If you cannot get the desired results using the "standard" views, there are various options for controlling the view from user code, but this will require more detailed knowledge of the usage scenario (for example, whether you need to work with a pager, etc.). If it seems to you that you need to go this route, you can improve your question with a description of what you need to achieve exactly.


Edit: As for the options for controlling programmatically, you can take a look at view module hooks . For minor adjustments to the query result, you can implement hook_views_pre_render() and directly manipulate the returned result set in $view->result (that is, after the request has been completed).

However, for large manipulations (for example, in your case), you could implement hook_views_query_alter() and configure the actual query before using it to return a result set. Care must be taken to change the sorting or filter criteria, but preserving the general structure of the returned data (for example, it should still contain all the fields that are awaiting presentation). Although this approach provides tremendous flexibility, you need to know that it is fragile with respect to subsequent changes applied to the view — if the definition of the view changes in such a way that the constructed query changes, the change made in hook_views_query_alter() may not work anymore, or cause strange results .

View hooks run for each view, so before making any changes you need to check the correct presentation (and ultimately display).

+1
source

Source: https://habr.com/ru/post/1305017/


All Articles