Active
Project:
References
Version:
7.x-1.x-dev
Component:
Code: node_reference
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
7 Dec 2009 at 16:26 UTC
Updated:
22 Apr 2013 at 03:38 UTC
Hello,
Would be great to have nodereference count table with views integration, to see how many nodes are referenced to a node per content type.
Comments
Comment #1
frankcarey commentedI'm trying to do this with the views_groupby module, which should work, but the node reference relationship is an inner join instead of a regular JOIN. It should be a regular join, so that we can use a group by and get a count.
Comment #2
frankcarey commentedlooks like it is impossible to get a regular join (according to views2 api), so I did it the other way. Listing all nodes, then adding a required relationship to the referenced field. Add the following fields to the view and put them in this order:
1) Title (w/ relationship to node reference)
2) Nid (no relationship, Label:Count)
3) Aggregate SQL: Group by fields (count, Fields to group on: Title, Fields to aggregate: nid)
You should get an output that looks like:
====================
Title | Count
====================
Some Title | 3
Comment #3
frankcarey commentednote: downside is that you can't get a zero count this way :(
Comment #4
frankcarey commentedYeah, this isn't going to work for me. I'm thinking about doing this pretty much the same way that comment count works, and i think what giorgio79 was suggesting in the first place.
See the {node_comment_statistics} table to see what I mean.
Comment #5
gilgabar commentedI had similar needs, so I created a CCK field type to do the counting rather than trying to get Views to do it. It updates the count both when the node being counted is saved as well as when a node referencing the node being counted is saved. You can check it out if you are interested.
http://drupal.org/project/nodereference_count
Comment #6
fgmnodereference and userreference for Drupal 7.x are now maintained separately in the References module: moving issue over there.
Comment #7
fgmCategorizing.
Comment #8
danielb commentedJust a note that gilgabar's solution of using a separate field could also be done with http://drupal.org/project/computed_field if it is stable enough
Pro tip: Computed Field can save your ass with displaying data about your node in views that isn't already available, although you often duplicate data to make it work, and it does require some PHP knowledge.
IMO a count of items in a view for a particular field is not Node/User Reference specific. It would be useful for any field that allows multiple values.
Comment #9
damienmckennaAnother temporary solution - add a nid field and use code like the following to customize the output (D7):
Comment #10
Stomper commentedIs this what you're looking for? http://drupal.org/project/entityreference_count
Seems like its similar to Gilgabar's module except for entities. Can someone please confirm
Comment #11
gilgabar commentedYes, entityreference count is a port of nodereference count that works with all entities, not just nodes.