Attaching Entities to other Entities I have two custom entities in a D7 site. One is 'additional' data on an entity, and I want to attach that data to the main entity every time it is loaded.

Within Entity/Entity API, how can I do that correctly? attachLoad sounded correct but seems to be Field related, all my data are not fields (yet).
I've seen modules use attach load as well, which is what you need to get it on the actual entity.

It also depends on your data structure if the base entity has a reference to the additional data entity, you could simply use the entity wrapper along with entity properties. You wouldn't actually have the data on the entity, but have it accessible via the wrapper. The advantage is that you only run extra queries (loading the entity) as required.

In code you would then do

 $entity = load_entity_function($foo);
 $enity_wrapper = entity_metadata_wrapper('entity_type', $entity);
 $additional = $enity_wrapper-&gt;addition-&gt;value();
 $additional_id = $enity_wrapper-&gt;addition-&gt;id-&gt;value();


In order to have the wrapper do this, you tell it about the additional entity in a hook:

/**
 * Implements hook_entity_property_info().
 */
function module_entity_property_info() {
  $info = array();

  $properties = array();
  $properties['additional'] = array(
    'label' =&gt; t('Label'),
    'type' =&gt; 'entity_type',
    'description' =&gt; t('description.'),
    'getter callback' =&gt; 'function_get_entity_id',
    'setter callback' =&gt; 'function_set_entity_id',
    'clear' =&gt; array('id_of_additional'),
    'schema field' =&gt; 'schema_of_additional',
  );

  $info['base_entity']['properties'] = $properties;

  return $info;
}


You need a function that will get or set the id from the entity. Depending on your naming convention entity modules come with some that you can use.