Combining results from node reference fields with multiple values

Events happening in the community are now at Drupal community events on www.drupal.org.
gg4's picture

I have view that uses fields and grabs node titles - all deltas - from a node reference field via a relationship. Is there a way to get views not to generate a new row for every title that is being returned?

I have a feeling this is getting into hook_views_pre_render() or views_query_alter() territory...

All thoughts and advice appreciated.

Comments

summary page

drm's picture

If you create an argument for your node - not the references, the node that you don't want repeated, and then don't provide the argument, you can choose to display a summary page as part of configuring the argument. Not sure if this gives exactly what you want, but it is one way to avoid multiple listings.

Thanks for the reply. Summary

gg4's picture

Thanks for the reply. Summary views are very useful.

I am basically looking for how I would go about getting noderefernce.modlue to return all values in an array or single row instead of separate rows in the view query. Or, at least where to start in approaching this problem.

A single row?

drm's picture

Is this a display issue - how the View displays the results?

I think it is more an issue

gg4's picture

I think it is more an issue of how views - or the ckk noderefence module - builds the query.

I can deal with formatting returned data from views, but I think I need to get at this problem before views runs its query. I am trying to figure out the best approach to go at changing what views asks for — whether this should be done through a views hook of some some. Or, through a new relationship handler or field handler and how to start that process.

I think maybe views_customfield module with custom sql might be a alright one-off solution. I would like to come up with something I can reuse.

I want to know the answer to this question too!

sidharth_k's picture

@_double Any luck in finding the answer? :-)

I found the answer!!

sidharth_k's picture

The answer is to use the following module

http://drupal.org/project/nodereference_views

I've tried it and it works like a charm. However this means that a view runs for every line in the "outer" view... this might be inefficient (unless it is optimized in some way...). You might consider rearchitecting your data structures.

Caching! Always cache views

merlinofchaos's picture

Caching! Always cache views like this.

See views_content_cache for an excellent caching mechanism.

The nodereference field

merlinofchaos's picture

The nodereference field itself should return just the titles for referenced nodes and can use the 'group multiple'. You cannot group a relationship.

Yes but what if you don't want titles?

sidharth_k's picture

@merlinofchaos, thanks for your response. I suggested the nodereference_views module in scenarios where you might want to get something other than the title of the node.

Using nodereference_views allowed me to get the following kind of table

Name of Company        |  Telephone Number of Vendors
==========================================
ABC                           | 1234
                                | 5678
------------------------------------------------------
XYZ                          | 6786
------------------------------------------------------

In the above example Company is a Content type and Vendor is a content type (the vendor content type contains a telephone number field). Company contains a field which is unlimited references to Vendor Content types.

Using nodereference_views allows me to pull out the telephone number from each vendor and show the table as above.

If I don't use nodereference_views I get

Name of Company              |  Telephone Number of Vendors
==========================================
ABC                          | 1234
-------------------------------------------------------
ABC                          | 5678
------------------------------------------------------
XYZ                          | 6786
------------------------------------------------------

i.e. ABC is repeated.

How can we solve this problem

mohini's picture

@sidharth_k: How can we solve this problem in drupal7 ?

I can say I banged my head on

scottprive's picture

I can say I banged my head on this issue (or an issue which is on the surface, identical). I got close, but then other issues demanded my time so I had to move on.

_double: It's not necessarily anything to do with cck noderef. I've had the same problem when dealing with database tables which are external to Drupal.

The direction I was given for crafting a solution was to create a custom views content handler to "get the row" the way people want to see the row (ie, concatenate all results in "Telephone Number of Vendors"). The Views API is sufficiently documented, if you know what to do and need to consult it it is all there.

All that said, I can not for the life of me find a comprehensive tutorial for this anywhere on the web (bloggers, here's your opportunity). The solution would probably be data table specific, but that's OK as it's relatively easy to take working things apart.

Is anyone in this discussion

christefano's picture

Is anyone in this discussion aware of the "Multiple Values for current companies" issue at https://drupal.org/node/968994? It affects anyone who lists more than one company on their Drupal.org profile. As it is, however, that issue has been postponed for the moment.

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: