Posted by henrijs.seso on June 3, 2009 at 10:35am
I am looking for a way to display count of nodes that reference to node being displayed in views table, for example, there are 6 nodes B that has node reference field pointing to node A, i want view to display list of nodes A with count of nodes B. Any tips, suggestions? Thanks.

Comments
I'm looking for the exact
I'm looking for the exact same thing. It's been about a month since you posted, have you found anything useful in the meantime?
yes, kinda
i found NodeReferrer module that is supposed to do that but it does something else and then there is a patch to do this but it still does not (i think) but this issue is not dead yet, so join forces there...
http://drupal.org/node/416332
Solved?...
Actually, I think I might have just come up with the solution... First, use the Views GroupBy module to add COUNT functionality to your Views query. Second, you have to change the way that you look at the query.
Instead of taking your content A and reverse linking your content B, you need to start with the content B, use the Relationships to link to your content A, then put the filters in place, your columns to display on your content A, and finally your GroupBy field. I'm about to give this a try. It's an excellent example of trying to take something designed for one purpose though and twisting it to what you want to do :P Also, I have a very limited timeline on my project, so I can't go doing too much work on contrib modules.
D5 only, need D6 (its about time, no?)
Views GroupBy module is D5 only. Fail.
ill have to do it anyway because date is not working via relationships :(
Automatic back references provided by Node Relationships module
You may want to check out this:
http://drupal.org/project/noderelationships
Another solution
Thank you Markus! That looks like a potential solution. I realized shortly into my solution above that the problem with it was that anything of content A which did not have any corresponding content B would not display...
Another solution which a coworker pointed out to me is the Computed Field module. If you're just wanting a count of content B, then you can use a Computed Field to calculate a count of content B on node save of content A. The only problem with this is that whenever you add or remove a reference, you'll need to make sure you resave your content A so that it can recalculate. It strikes me that the Node Relationship module is better for two way references and for anything complicated, but since all I want is a count, I'm going to try the Computed Field module for now (harder on content submission, but faster on content displaying).
results?
well? anything new?
how are you planing to automatically resubmit node types A after you change node type B?
New field formatter to display back references count
Hi,
I have just added a new formatter to the Back references field provided by Node Relationships module that displays the count of back references. This formatter does not run the view, but a dynamically customized query against the referring field table filtering by the nid of the referenced node.
This feature should be available in Beta 3 of the module.
The good thing with this module is that you don't need to duplicate data in referrer fields. That's inefficient and prone to generate inconsistencies.
To monitor inconsistencies in node/user reference fields, I have also written the Referential Integrity for CCK module (a beta should be shipped soon).
Cheers
hmmm, promising
cool, ill check it out...
Not what I was looking for, but found something else
I checked out the Node Relationships module as it seemed like the more extensible solution. It is not what I want... Instead of making a two way relationship between nodes, it creates a view for doing the back-reference and allows you to set the result of the view as a CCK field. This means that a listing view of a node would have to have a sub-view executing for each item to display information on nodes which refer to it. A much more elegant solution would be to just have the relationship be two ways in the first place rather than making it one way and trying to twist it into doing what you want.
Until this happens, I have found another somewhat hackish solution in another contrib module that leaves me with a slightly better taste in my mouth, Corresponding Node References. It's a module for when you have Node B reference Node A, an automatic reference is also created from Node A to Node B. This is a solution I was joking about doing with coworkers as it goes about creating a circular reference... My coworker actually suggested the Computed Field approach to avert this apparently necessary evil, but as I would like to do other stuff with the two way link besides just getting a count of Node B instances referencing Node A, I think my hand has been guided.
sad day for me
Corresponding Node References works if both content type node references are set to unlimited values, but one of my node references is created automatically with node reference widget that disables me to set values to unlimited. ill continue to investigate.
Victory!
i got count of refering nodes in views using NodeReferrer module and patch found here: http://drupal.org/node/416332.
Before i could not find where to look but now i know better - look under NODE in views fields, you will find Nodereferrer: by node type (or field) and in config options you'll have choice to display count...
you will end up with nice number :)
I got it working with a different setup
First off, the Views GroupBy module is for Drupal 6:
http://drupal.org/project/views_groupby
I think you were looking at the Views 'Group-By' Pack module (understandable confusion :P) which is only for Drupal 5:
http://drupal.org/project/views_groupby_pack
Using the Views GroupBy module along with the Corresponding Node References module, I was able to get the information I want. I wanted a one to many relationship for my nodes, which is the only type of reference that Corresponding Node References doesn't support (or rather enforce). This was fine for me as I am managing the relationships for the users on my site rather than providing them with a selection field.
As for the Node Relationship enhancement mentioned by markus_petrux above, that sounds excellent. My only concern would be as to whether the tables have been properly indexed to support your query. From initial inspection, the default table format as generated by the Node Reference module is not conducive to checking a node reference in reverse.
Dynamically generated indexes? hmm...
That's a good point indeed.
Just created a feature request to remind me that this is a must! Thank you! :)
Ref.: #518102: Optimize back references views with dynamically generated indexes
There should be a way to defer the creation of indexes, maybe using cron, maybe using batch api, maybe just warning the admin so it can be done at a fully controlled batch window by the admin itself, which might be a must if the site is big enough.
Indexes for noderefs will be available from CCK itself :)
You may want to watch this issue: #231453: Allow indexing columns.