Mad Scientist
Mad Scientist

Reputation: 18551

Drupal: Display only specific NodeReferrer field in Views

I have a content type appointment with a date field that references nodes of the content type person using the Nodereference module. In the content type person I added a Nodereferrer field that shows the reverse of this references (Person -> appointments).

I now want to create a view of person nodes that shows the last appointment date of that person. I can create a View of persons with a relationship to appointments that displays all appointments, but I have no idea on how to display only the most recent one.

Any ideas on how to achieve this?

Upvotes: 0

Views: 817

Answers (2)

migimaru
migimaru

Reputation: 229

Instead of adding the Nodereferrer field to the view, try adding the Nodereferrer relationship then adding the Node title (using that relationship) as a field. You should be able to sort from newest to oldest, and then set the view to be Distinct so that only the first row for each person shows up.

Upvotes: 0

Jeremy French
Jeremy French

Reputation: 12177

Personally I have not had much success with using views and node reference. It never seems to work out the relationships properly.

So my advice would be to write your own query. If you look here you can see a way to override the SQL generated by views, so you still get a lot of the goodness which comes with views.

By the way I would be very interest to see if there is a better answer than this

Upvotes: 1

Related Questions