I'm implementing a site for brainstorming. The notion is that users of the site can post 'problems' and other members of the community can post 'ideas' to solve those problems (like Yahoo Answers).

What I've done:
- created two new content types: problems and ideas.
- within the 'idea' content type, added a node reference (autocomplete text widget) field called 'related problem'. The intent of this field is to allow the creator of the 'idea' to reference the 'problem' their idea relates to.

What I need to accomplish:
I would like the 'problem' content type to have a field which automatically displays all of the 'idea' nodes which reference it (that's what I think of as a reverse node reference).

Example:
- problem A is created.
- ideas X, Y, and Z are created which have a node reference to problem A.
- when problem A is viewed, I would like it to show that ideas X, Y, and Z have been suggested as solutions.

Thanks in advance for any ideas,
Steve

PS - I would rather not just rely on comments to the 'problem' content type for people to add their ideas. The brainstorming work flow that's being implemented would need to allow people to contribute ideas without necessarily having a problem to associate it with. The ideas also need to be their own nodes so that we can flag them as they go through various stages (initial, evaluation, execution, archive, etc).

Comments

boneless’s picture

what about creating a new field type, let's say 'reverse reference'?
instead of choosing a reference you can select an existing node refence field and all nodes referencing this node will be displayed.
shouldn't be too difficult to do.

Anonymous’s picture

It doesn't appear to be as automatic as that. When I use the existing node reference field, it doesn't display the reverse node information (it would be slick if it did).

I'm thinking I need some sort of computed field and have been investigating that approach.

Thanks again for the suggestion.
Steve

thomie’s picture

This could be achieved by using the Views module. More info in the Handbook.

Anonymous’s picture

... and maybe that's easier, but I would still like to display the related nodes information within the content type itself. That's why I'm trying to stick to CCK-based solutions.

jastraat’s picture

You can use node relativity to create 'parent' and 'child' nodes. And the module provides blocks by default that show all of a node's 'children' on the parent page and all the 'parents' on the child pages.

------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)

thomie’s picture

that might the easiest solution.

I was thinking using Views module and some custom php, see 'inserting views' from the handbook. This would go something like:
1) Make your view: a list of all 'ideas' that have a nodereference to a given 'problem'.
2) Make a custom module, implementing hook_nodeapi.
3) In your_module_nodeapi(), add the view to all nodes of type 'problem', using $op=='view', views_get_view() and views_build_view().

But I don't know if that first step is even possible. Next 2 steps shouldn't be too hard.

jastraat’s picture

If you went that route, would there be any reason you wouldn't simply use the view field module to add a view field to the problem node type? (You can set it to default to the view you created for the purpose)

------------------------------
http://fraggles.artsci.wustl.edu (Drupal user documentation and development blog)

thomie’s picture

maybe because you like to get your hands dirty, use as much custom php as possible, learn how to write modules, learn about the inner workings of Drupal. So that one day when there is no module available for something you want, something really advanced, you'll be prepared.
Or something.
Yes, so I agree again. Relativity module or Views + viewfield.

twen’s picture

I have the same problem than you, and here what we did find out :

Create a view, that will display the ideas from an argument.
Use the CCK-dev module. Add a node reference to the problem form. At the very bottom of that field configuration page, select the previous view, and add the argument.

Apparently the node reference field in the CCK module, has the same capability that viewfield module, except it's right within a node.

You can also use viewfield module. Add then a viewfield field in your problem form, and select the view you want to display.

Curiously viewfield module and nodereference in CCK module are doing the same now.

Walterh’s picture

I still don't see how to make a view with a parent and his childeren on 1 page.

I would think this is a basic view that a lot of people will use. I'm working for quite a while on it, but cannot get this view. I've used views, viewfields, view-fusion,

- (viewfield works but is a dirty solution because every node contains a field with the name of the same view)
- ("node family" is not an option because I have to use "node reference" because my data is imported)
- (view-fusion seems a good option, but I cannot figure out the right view)

Anyone with suggestions?

-----------------------------------------------

derhasi’s picture

It seems to work with views and computed field:

Settings for the computed field:
------------------------------------------------
Computed Code:

// ensure the node has an id by saving it if it is new.
if (!$node->nid) node_save($node);
// store the nid in our computed field
$node_field[0]['value'] = $node->nid;

Display Format:

$display = theme_view('test', NULL, NULL, 'embed', array($node_field_item['value']));

Store using the database settings below OFF ( I don't know, if it makes a difference when set to ON)
------------------------------------------------
'test' is the name of the view, which shows all referenced nodes of the actual node (nid = argument#1).

I'm just testing computed field and CCK but it seems to work.

Hope it works for you too.
If there are any problems (e.g. for security) please let me know.

matherion’s picture

Hey all,

I've been looking for what I think is the same thing, and recently, somebody created it!!! Check this post about the Nodereferrer field in Drupal 6.

Matherion

markus_petrux’s picture

http://drupal.org/project/reverse_node_reference

It implements a Views Relationship, so there's no need to duplicate relationship data in the database, which is prone to inconsistencies.

Doubt is the beginning, not the end of wisdom.