This has been asked a lot and no great answer was ever available and many work arounds were offered but all with extra computing needs ie rules, flags, etc.

http://drupal.org/node/427072
http://drupal.org/node/364425

This is particularly important when you have a node reference in which you use the "Advanced - Nodes that can be referenced" option selected and you want to reference a node that has not yet been referenced.

Example
You have content type TEAM which references content type TEAM LEADER. You are using "Advanced - Nodes that can be referenced and you want your view to only show TEAM LEADERS that are not yet referenced by a TEAM.

The latest Node Referrer module Beta 2 solves this by adding the ability to use a Relationship with the node:Node referrer option.

View Node Type
Add relationship, Node: Node Referrers, use the field that refers to TEAM LEADER . Label "Referencing Nodes"

Filter Node Type, TEAM LEADER

Filter Node:Nid, Relationship: "Referencing Nodes", Operator is empty (NULL).

Add the fields you need and save. This should list all nodes of type TEAM LEADER that have not been referenced by nodes of type TEAM.

Comments

mattiasj’s picture

Can't thank you enough for this great documentation.

marvix’s picture

I have Article content type, and Featured Article (FA), the FA have only reference filed to the Article to list the FA alone.

I have done what you said here exactly 100% ... but still showing all the articles ... what could the wrong here !!!!!

1. Node view type fields.
2. Relationships : FA: field_featured_node
3. Filter: Node Type : Article
4. Filter Node Nid : empty, Relation field_featured_node
5. Fields Node Title.

thx

tpainton’s picture

Okay, so you have a content type called Article. You also have a content type called Feature article that references article and you want to list ? All featured articles?

All you need to do is create a view with node type featured Article, then have your field be content:noderference field_featured_node.

This should list all of your featured articles. If you want to list all articles that are NOT featured. Then you have to have the nodereferrer module installed and you must use the relationship "Node: Node Referrers field_featured_node.

Filter Node Type, Article

Filter Node:Nid, with Relationship: "Referencing field : field_featured_node", Operator is empty (NULL).

This should list all articles that do not have a reference to them from Featured Article. It sounds like you are not using the node referrer module.. You must use this.

vistree’s picture

... is it possible to limit the relation on a specific content typ?
I made "the fault" that I used the same nodereference-field in different content types.
But I have to display only the nodes having NO refferer to one of this content types.

Using your example:

You have TAEM with reference to TEAM LEADER.
You have also INVOICE with reference to TEAM LEADER.

TEAM LEADER 5 is referenced by INVOICE xxxx but has no TEAM - So I want to display him using your method.
In the moment he is not in the list of TEAM LEADERS without TEAM, as he has an invoice ;-(

Can I solve this without adding a new reference field??

Kind regards

Kai

tpainton’s picture

So, invoice and team both have the exact same field?

The relationship should filter the two apart if they have different fields field_invoice_manager and field_team_manager.

if they have the exact same field label then you need to change them as above.

vistree’s picture

OK, thank you. So I will change one of the fields.

Kind regards

vistree

ressa’s picture

Thanks for the example. I spent a whole evening trying to make it work, until I finally realized that the default CCK Node Reference module, which is part of the CCK package, isn't Node Referrer, which is a "helper" module. I just assumed I had Node Referrer installed, because I could refer nodes. Perhaps that should be emphasized a bit more?

So to those that can't make it work, and can't see the "Node: Node Referrers" when you click on 'Relationships', install the Node Referrer module! http://drupal.org/project/nodereferrer

"Advanced - Nodes that can be referenced (View)" refers to the bottom of the content types' node reference field editing page. In stead of ticking off which content types can be referenced, you can use a view to select the nodes that can be referenced. As far as I can tell, it isn't needed to show which nodes don't have a reference yet.

Let me just add that Node Referrer is a pretty great module, enabling showing referrers under a referenced node: http://drupal.org/node/431308

bekirdag’s picture

This solves the problem if you don't want to do it for a user spesific view.
But what if i want to list the teams the hasn't been referenced by the user x?

Tino’s picture

Thanks for this tutorial! It had been very helpful.

I am running into one critical problem though...

When editing an existing TEAM, and I do not want to change the referenced TEAM LEADER, that is not possible anymore. The current TEAM LEADER is ruled out by this view (because it is already referenced).

How could we fix this?

summit’s picture

Hi could you post your view please? I can't get it to work using Views 3 and latest nodereferrer module.
Thanks a lot in advance,
greetings, Martijn

tpainton’s picture

I am sorry, I don't have the view any longer, make sure you have the nodereferrer module loaded in addiction to CCK, as above, my original post was vague on that. If I have time I can create a view and post it but I am banging my head on a jquery issue that has me up too late too often right now! :(

core44’s picture

Thank you very much for pointing this one out. A great help to me.

On closer inspection I've noticed I'm having the same problem as above. When using the view as the source for 'nodes that can be referenced' in a node reference field, it limits the selection perfectly to nodes that haven't already be referenced.... but, if you then edit the node, the reference field can no longer access its original value, as it's no longer available to the view as an 'unreferenced node'. The field defaults to none and loses its reference. Its a shame as it would have been a very nice way of forcing unique node references. I feel like Ive possibly just said 'reference' too much. Reference.

serpicody’s picture

I followed your instructions and they worked perfectly. Now I need to take it a little further.
To use your language: My TEAM content type has other variables that we'll call COLORS. I need to list TEAM LEADERS that haven't been referenced by TEAMS of certain COLORS and be able to expose those filters.
Anyone?

tpainton’s picture

Think the only way to do that is to create a view for each color team that draws from the same stack of team leaders.. The problem is that the logic works by selecting a team leader because the back reference to it is NULL. If the back reference is NULL? How can you tell what color it is?

A long winded work around would be a different view for each team. The best way to do this is a custom module which could do it easily and quickly. Views is great for building common tables quickly, but it breaks down when you need some complex logic added.

vkouroub’s picture

How about listing nodes NOT being referrenced by another node TO the corresponding user who has note referrenced them? I bet there is no solution without coding.

tpainton’s picture

I'm a little confused by question.. not you're fault. This makes my head all spinny.
Can you elaborate?

vkouroub’s picture

Ok sorry explaining :

Lets say i have managed to show all nodes NOT being referenced by another node in a view.

Then how can i create a view listing all nodes NOT being referenced by another node on a per referencer user basis.

Meaning for EACH user this view will show: ONLY those nodes to which he/she has not yet created a node referencing to it.

This can be useful when someone wants to show a "Reference Me" link (or a nice image link) on a parent node but only to those users who have NOT YET created a node referencing to that particular parent. Basically this will permit only one node reference per parent node also.

I have been banging my head for a month now, to do this on views (without coding) with no results. I can manage to hide the "Reference Me" link for all those users who have created a node referencing to the parent node but i CANT show that link on a NON user referrrer basis.

In other words if there was a way to inverse the Node Referrer Relationship and then tie it to the USER Current Filter then i would have achieved this.

Who ever has a solution for this is a GOD.

Thanks.

tpainton’s picture

So basically a view of users who have not created a node that references a target node.

We can create a view of nodes that don't reference the target node.
If I understand your logic, we need nodes. If the user hasn't created the node, then we can't make a list of them...

I believe you need a custom module.

tpainton’s picture

I now need to provide a view of nodes of type A that are not referenced by a B node created by the user..

I'll post up the view once I figure it out.. Hopefully...

arnaud-brugnon’s picture

Awesome
14 years later, this documentation still works like a charm.

Thank you.