Would it be possible to display the node reference count value as a Views field similar to how the "node: comment count" field?

I have created a content type (A) that has another content type (B) that automatically references the original content type node using the node reference url widget. I would like to display the the number of times A is referenced by B in a View.

Is this possible with this module or must this be done using a computed field (http://drupal.org/project/computed_field)?

Thanks

Comments

gilgabar’s picture

Maybe I misunderstand, but a Views field is already provided. Look under 'Content' and it is named whatever you called it in CCK.

Stomper’s picture

Thanks for the reply. I did find the Views field you mentioned but I am still having issues.

I have two content types, one is a question content type and the other is a answer content type. The answer content type has a node reference field to a specific question content type. I have added a nodereference count field to the question content type. The question content type already has two answer content types associated with it (two nodereferences to the same node). FYI, The nodereferences were made prior to adding the nodereference count field to the content type, if that affects anything.

In configuration of the field I have selected the correct node reference field under "nodereference field that can be counted." In Views, I have selected the the correct field under "content:..." as you noted previously, but it is not displaying the correct value.

Technically, the View should be displaying the value "2" but it currently is displaying nothing. I added some "empty" text in the View to see if it was reading the value correctly and when I checked the View output it displayed the "empty" text. This must mean that the nodereference count isn't working correctly. I cleared the cache to see if that would remedy it but it did nothing.

Also, in the Views field options under "format," I tried both "Default" and "Non Zero" to see if either would do anything, neither worked or at least produced the correct output.

Any suggestions?

Thanks

gilgabar’s picture

"FYI, The nodereferences were made prior to adding the nodereference count field to the content type, if that affects anything."

This is most likely the issue. If you read the Readme file you will find instructions on how to update the count of pre-existing nodereferences. That should solve the problem.

Stomper’s picture

Thanks again, the README fixed it.

Perhaps you should include some information on the modules project page stating that for pre-existing nodes the VBO module is needed, as well as a suggestion to read the README. This should help a lot of new users as well as stop the same issue being created again and again.

One quick question about the module. Since I have used the module as View field, I noticed that in the configuration for the field there is a "format" option with two choices - default, and non zero. Could you please explain the significance and usage of each option, please?

Your module is really helpful and did exactly what I needed it to. Greatly appreciated both your module as well as your help to fix my issue.

From README.txt:

Updating counts for pre-existing nodereferences
-----------------------------------------------
While the nodereference count fields will be updated when the node is saved or when the referencing node is saved, that isn't much help for pre-existing nodereferences to nodes created prior to the addition of a nodereference count field. The Views Bulk Operations (VBO) module, http://drupal.org/project/views_bulk_operations, is the recommended solution . Using VBO you can re-save all of the nodes that have a nodereference_count field. That will update the count for each of those nodes. The specifics will vary for each site, but the general instructions for doing this with VBO are as follows:

- Install the Views and VBO modules if you do not already have them installed.
- Go to /admin/build/views/add and create a new node view.
- Create a new page display.
- Change the style from Unformatted to Bulk Operations.
- Select 'Use Batch API' under TO EXECUTE OPERATIONS.
- Check 'Save post (node_save_action)' under SELECTED OPERATIONS.
- Click 'Update default display'.
- Add a path under Page Settings.
- Add 'Node: Title' under Fields.
- Add 'Node: Type' under Filters. Be sure to select the node types that contain nodereference_count fields.
- Save the view.
- Visit the path that you set for the view.
- Select all the nodes.
- Click 'Save post'.
- Your nodereference_count fields should now be updated.
- You are unlikely to need to use the view again, so feel free to delete it if you like.

gilgabar’s picture

Status: Active » Closed (fixed)

Putting the VBO info on the project page is a good idea. Though the name of the README file is itself a command to read it, so I don't know that saying it again will influence anyone not already inclined to obey.

I'll have to update the README with a quick mention of the non-zero formatter as well. It is for the use case when you only want to display the count if there are things to count. So if there are zero references then it would not display the field, but if there are one or more references it will display it. The default behavior is to display a count for zero or more references.

akishankar’s picture

Issue summary: View changes

I am using:
Drupal v 7.41
Node Reference Count v 7.x.1.0

I have two content types say 'A' and 'B'. The content type B has a field that refers to content type A.
I have added count field to content type A ( to get the count of 'how many content of type B' refers to A ).

When I add a content of type B and refers to some content of type A, the count field in content type A does not get updated. However when I edit that particular node of type A and save it, the count updates.

I have used the count field to display on view and unless I explicitly save the content type A, I do not get the updated count.

Please suggest.