How to delete a node with same specific field content and by same user when a more recent one is created in drupal 7? I have created a review system allowing users to make a review of a place. One of the fields for each review is the actual location which needs to be filled. If a user decides to create a review of 'the Red Lion' and it happens that she has already written one on that place, I want the old review to be deleted, and only the latest one kept.

I have tried to use Rules with the 'fetch entity by property' and a double loop, but it does not seem to do the trick. Here is the export of a test rule where I just flag the 'former review'. The current result is that it flags all reviews of the 'Red Lion' made prior to the current one being saved. Any suggestions?

{ "rules_delete_old_reviews" : {
"LABEL" : "Delete old reviews",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "flag" ],
"ON" : { "node_presave--review" : { "bundle" : "review" } },
"DO" : [
  { "entity_query" : {
      "USING" : {
        "type" : "node",
        "property" : "author",
        "value" : [ "site:current-user" ]
      },
      "PROVIDE" : { "entity_fetched" : { "entity_fetched_author" : "Fetched node by author" } }
    }
  },
  { "LOOP" : {
      "USING" : { "list" : [ "entity-fetched-author" ] },
      "ITEM" : { "list_item_nodeauthor" : "Current list item" },
      "DO" : [
        { "entity_query" : {
            "USING" : {
              "type" : "node",
              "property" : "field_revlocation",
              "value" : [ "node:field-revlocation" ]
            },
            "PROVIDE" : { "entity_fetched" : { "old_review_item" : "old_review" } }
          }
        },
        { "LOOP" : {
            "USING" : { "list" : [ "old-review-item" ] },
            "ITEM" : { "list_item" : "Current list item" },
            "DO" : [
              { "drupal_message" : { "message" : "This node \u0022[list-item:title]\u0022 is now flagged." } },
              { "flag_flagnode" : {
                  "flag" : "tagged_review",
                  "node" : [ "old-review-item:0" ],
                  "flagging_user" : [ "site:current-user" ],
                  "permission_check" : "1"
                }
              }
            ]
          }
        }
      ]
    }
  }
]
  }
}
Here is how I achieved it in the end:

First, create a component rule 'Listreviews'. This component rule will filter nodes created by the current user and then 


Component plug-in is set to 'rule'.
The variable is of type 'node' of type 'parameter'. Give it a machine name 'nodefromlist' and save.
Add a condition: data comparison. This comparison will be have the data selector nodefromlist:author:uid, and it needs to equal site:current-user:uid.
Add an action: 'delete entity', which will have the data selector value of 'nodefromlist'.
Save!  


Then, create a rule 'Delete duplicate review'.


the event chosen is 'before saving content type review'  
no conditions  
Actions: 'fetch entity by property'

entity type 'node'  
property: the field 'location' (in my example)  
data selector: go down the arborescence up to: node:field-location  
I put a limit of 10, but may need to be adjusted based on previous content available.  
Add a label to the provided variables section  
Add a variable name like: item_same_location  



Then


Create a loop below the action above with the parameter item_same_location  


call the current list item: list_item.

In that loop, create an action 'component' with the name of the rule component created above.


the data selector will be: list_item.

Save your rule!


This should now work. As a bonus, I added a 'display message' action in the component rule in order to let the user know that their previous review was deleted. I hope this helps someone in the future!