How can I get a relation by the endpoints using the "Fetch entity by property" action in rules? Short version: I want to fetch a relation by the endpoints.  The relation already exists in the database.  How can I use the Fetch entity by property action to return the relation?

Long version:

I'm using the Rules and Relation modules on Drupal 7.  I have a relation type that is created between two users (the endpoints are user entities).  The relations I am trying to fetch have already been created.

When one user sends a message to another with the Private Message module, I want to fetch the relation between the sender and the recipient.

Here is the rule:

Event: A message is sent (from Privatemsg module)

Action: Add a variable (List of any entity items, endpoint_list)

Action: Add an item to a list (Add privatemsg-message:author to endpoint_list)

Action: Add an item to a list (Add recipient to endpoint_list)

Action: Fetch entity by property (Entity type: Relation, Property: Endpoints, Value: endpoint_list, Limit results: 10, provides fetched_relation)

However, when I try to perform another action (loop, data comparison, data set, etc.) on fetched_relation, I get the following error in the rules debug log:


  4.468 ms Unable to get the data value for the variable or parameter value. Error: Missing data values.


It appears that the relation is not fetched.  However,


I am sure the relation exists in the database with the correct endpoints (the relation appears in the UI correctly and I even checked the MYSQL table).
When I add an action Print message and print privatemsg-message:author:name and recipient:name, it shows me the names of the correct users, so those variables appear to be correct.
I have looked at the documentation for fetching relations with rules but I can't see what I am doing wrong.
I have managed to fetch relation by endpoint with the help of @marcusx and the patch of @MahmoudMostafa (drupal user names). You can find all in the issue Fetch Relation by Endpoints in rules.
I had also linked your issue to that one.
Resuming the steps here, you need to:

apply the patch



Create a list of any entiy
Put your endpoints in the list
Use the endpoint list to fetch the relation

cited from marcusx comment

(I see you already know this).
Bear in mind that

&quot;fetch relation by endpoints&quot; action in rules, [...] fetches all the relations for the endpoints in the chosen list, even if the list contains only one endpoint.
In this (sub)case, the action fetches all relations pointing to the selected endpoint, whatever the other endpoint.
cited from my comment

And that the resulting fetched_relation is a list (I see you already know this as well).
I believe you only need to apply the patch, which you didn't mention in your question. Is it true?