2

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,

  1. 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).
  2. 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.
  3. I have looked at the documentation for fetching relations with rules but I can't see what I am doing wrong.
  • Just a humble thought - a shot in the dark really. In some cases, in order to work with a particular field (e.g. a noderef attached to an article) we have to tell Rules that this field exists (adding a condition: entity has field...|| node is of type article). I'm just wandering then if the errors perhaps stem from a missing object? Got this idea while watching this screencast nodeone.se/sv/node/754 – Bisonbleu May 22 '13 at 1:46
  • @Bisonbleu Thanks for the idea, but in this case, I am setting the type of all variables upon declaration and fetching entities by property, so as I understand it Rules must know what types are being used. – Patrick Kenny May 22 '13 at 1:53
1

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:

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

cited from marcusx comment

(I see you already know this).

Bear in mind that

"fetch relation by endpoints" 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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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