Score:1

How to create a view printing the latest 3 nodes with unique entity reference values

nl flag

I have two content types, CAR and DRIVER. The DRIVER content type contains a CAR entity reference field. So each DRIVER node creation page can reference a specific CAR.

The goal is to build a view to print out 3 of the most recent unique CARs referenced from a DRIVER node (created by the logged-in user).

Example... here are 6 of the most recently created DRIVERS by a particular user.

  • Driver 1 - BMW
  • Driver 2 - BMW
  • Driver 3 - Mercedes
  • Driver 4 - BMW
  • Driver 5 - Audi
  • Driver 6 - Mercedes

The goal is to display 3 of most recent unique CARS referenced, like so...

  • Driver 1 - BMW
  • Driver 3 - Mercedes
  • Driver 5 - Audi

The closest solution I've found is using Aggregation in views, but the sort order by Created Date doesn't actually sort them correctly.

I'm open to building this outside of views also. Any suggestions? Thanks!

blur avatar
bn flag
How is the 'Cars' reference defined? Taxonomy? Entity reference? Also, the logged-in user can have multiple drivers? Is this correct? I'm trying to figure out how a relation between Driver and Car can be established. Is the car a defined value (like a taxonomy term) or is it a value the user can type in? If it's the latter, this will be harder to do because there wouldn't be a unique ID that can be used. Once this gets figured out, you can sort by # of results and filter down to the top 3.
nl flag
'Cars' and 'Drivers' are both Content Types, and Cars are referenced via entity reference field on the Driver node add form. Yes, the logged-in user can create multiple drivers. Yes, Cars are predefined values (has it's own unique ID) as it's a previously created node. Still, the issue remains... narrowing down the latest 3 Drivers with unique Cars (not duplicating the Car value). Thanks!
blur avatar
bn flag
Are you able to pull in 3 car/driver combinations? Even if they aren't unique?
nl flag
Yes, I can via Views. And I can make them unique using aggregation. But trying to sorting by DATE breaks the aggregation.
pinueve avatar
mx flag
try sorting by NID
nl flag
Tried it, but since it's being aggregated/grouped by CAR, and I need it sorted by the created date of DRIVER... setting sort to the DRIVER's NID breaks aggregation.
Score:-1
je flag
  1. Create a view for Car content type
  2. Add a relationship to Driver content referencing this content
  3. Sort by created date using the Driver relationship
  4. Use aggregation to show distinct values
  5. Use pager settings to only show specific amount of items
nl flag
Doesn't work... the "sort by created date" with aggregation doesn't display results as you suggest.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.