Question:

Need To Update One Entity Through Another

Luke: 2 weeks ago

I've been trying every angle I can, but I keep running into Revision ID errors when I try to update a referenced or related entity of another entity. I believe this might be on the right track (http://drupal.org/node/996696)? I'm not sure why these are occurring. I just need a simple field to be updated when the related entity is updated.

It also throws this error: DatabaseTransactionNoActiveException (http://api.drupal.org/api/drupal/includes!database!database.inc/class/DatabaseTransactionNoActiveException/7)

Is there any documentation on how to update one entity when another is updated? I just need to be pointed to the right track on this one.

Answer:
Brooklyn: 2 weeks ago

Okay figured it out. I needed to patch the Redhen module (http://drupal.org/node/1592686#comment-6936186) I'm using which was causing a Revision ID error. Im using the Relation, Rules Redhen modules together (and of course the Entity API). Here is the export of the Rule that did it:

{ "rules_update_employment_status" : {
"LABEL" : "Update Employment Status",
"PLUGIN" : "reaction rule",
"REQUIRES" : [ "rules", "relation" ],
"ON" : [ "relation_update" ],
"IF" : [
  { "entity_is_of_type" : { "entity" : [ "relation:endpoints:0" ], "type" : "redhen_contact" } },
  { "entity_has_field" : {
      "entity" : [ "relation:endpoints:0" ],
      "field" : "field_employment_status"
    }
  }
],
"DO" : [
  { "relation_rules_fetch_endpoint" : {
      "USING" : {
        "relation" : [ "relation" ],
        "entity_type" : "redhen_contact",
        "number" : "1"
      },
      "PROVIDE" : { "endpoint_fetched" : { "endpoint_fetched" : "Fetched Endpoint" } }
    }
  },
  { "data_set" : {
      "data" : [ "relation:endpoints:0:field-employment-status" ],
      "value" : "20"
    }
  },
  { "drupal_message" : { "message" : "[endpoint-fetched:full-name]\u0027s Employment Availability has been changed to [endpoint-fetched:field-employment-status]." } }
]
  }
}

This let me access whatever fields on the endpoint that I wanted then change them if I needed to.