3

I have a view made up of nodes that include node reference fields. I would like to pull in a field from each of the nodes being referenced for display in my view.

I know that is a little confusing so let me give you an example.

  • My food content type contains the name of a food and the number of calories it has.
  • My diary content type contains a date and a node reference that accepts food nodes.
  • My view displays your diary nodes.
  • I would like to display the calories for each food item that is being referenced by diary
  • I would like to add the calories using views_calc (or something else).

The way I see it there are two ways to do this - either add a calories field to my diary content type that automatically pulls from the node that is being referenced, thus making it available to my view. The other option is for views to be able to pull in fields (sub-fields?) from a node reference field.

I don't know if either option is possible or, if it is, how I would go about doing it. Any help would be greatly appreciated.

Edit: Relationships will allow me to pull in the fields I need, so now I just need a way to add them. Views_calc does not support calculations on relationship fields.

1
  • 1
    do you mean Drupal 6 or 7, specifically?
    – Alex Weber
    Commented Apr 6, 2011 at 21:48

3 Answers 3

3

Shouldn't be too hard with a Views Relationship.

As you've mentioned, your View should show content (nodes). Here are the rough settings, as I see it:

  • Filters: Published or Admin; Content Type: Diary
  • Display: Fields
  • Relationships: Content-food nodereference field
  • Fields: Food (no reference...from the diary content type); calories (from the referenced food field)

That should about do it. I usually have to tweak Views relationships a bit to get them to work perfectly, so it's a bit tough for me to get it exactly right without seeing your content.

Best, Scott

1

I outlined my solution for getting this to work with views_calc here: http://drupal.org/node/416670#comment-4313730.

1
  • 1
    May you summarize what reported in that comment? An answer that just contains a link is not considered an answer.
    – avpaderno
    Commented Apr 30, 2011 at 4:01
0

If you want more control over what gets pulled in without using a relationship, try Views Field View

It allows you to embed a view as a field within another view. Arguments pass from the outside view to the embedded view.

I've found this useful when trying to create a view that displays fields from a node_referenced node.

Kim

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.