1

Scenario

A content type - Wardrobe references another content type Product via Entity Reference field - field_product.

Problem Statement

I need to find the Wardrobe content which most recently referenced a particular Product content.

Question

Could this be accomplished through Views alone (by playing with available options in views) or do I need to write a customised query in php? I cannot figure out the way with either of these options :/

P.S.

Alternative suggestions are welcome :)

1 Answer 1

3

I am afraid, it's impossible to achieve what you want with a simple entity reference field alone.

The problem is that while the wardobe content saves the date of its most recent edit, you can not tell which (if any) product was added during that editing session (unless you use versioning consistently and compare the products saved in different versions manually). To complicate things further, an entity only saves the date of its most recent edit (saving over the previous edit date) which makes it very inadequate to track when a particular product was added to a wardrobe.

The biggest issue you face is that the information you need (when an item is added) is not directly tracked at all. While you could probably figure it out if you use versioning, this data would still be very hard to access in views.

What you can do is make a list of wardobes a particular item is part of and order them by most recently updated wardobe (though this most recent edit may or may not have actually added that product). If that's not what you want you need to find a way to track the missing date information yourself.

Possible starting points which come to mind:

  • Custom compound field with joined reference + date fields: https://www.phase2technology.com/blog/compound-fields-in-drupal-7/
  • Custom module which adds a db table with columns for wardrobe id, product id and date. You can access these data on node save, during which you can still access the old version of the wardobe, check which (if any) products were added, and add those entires to the db.

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.