1

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!

6
  • 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.
    – blur
    Aug 28, 2021 at 1:22
  • '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!
    – Yuckle
    Aug 29, 2021 at 2:35
  • Are you able to pull in 3 car/driver combinations? Even if they aren't unique?
    – blur
    Aug 31, 2021 at 21:47
  • Yes, I can via Views. And I can make them unique using aggregation. But trying to sorting by DATE breaks the aggregation.
    – Yuckle
    Sep 1, 2021 at 22:04
  • try sorting by NID
    – pinueve
    Sep 2, 2021 at 14:06

1 Answer 1

-1
  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
1
  • Doesn't work... the "sort by created date" with aggregation doesn't display results as you suggest.
    – Yuckle
    Aug 31, 2021 at 16:40

Your Answer

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

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