EntityStructureWrapper for file field is not being inflated properly while iterating While trying to interate over file filed values, EMW cannot being created properly. using isset() for not iniated fields and then trying to set them is not helping.

I get the error:


  EntityMetadataWrapperException: Unknown data property
  field_discipline. in EntityStructureWrapper->getPropertyInfo() (line
  335 of
  /var/www/siradisisporlar.com/sites/all/modules/ssbasic/entity/includes/entity.wrapper.inc).


Note that file wrapper here is EntityStructureWrapper and node wrapper is EntityDrupalWrapper.

All properties of other entity reference fields, etc are being reached properly.

$filew::data is array and it has fid where $nodew::data is a proper node object.

mymodule_node_insert($node) {
  //.... ..... $nodew is node wrapper
  foreach ($nodew-&gt;field_media as $delta =&gt; $filew) {
    $a = $filew-&gt;field_taxonomy_entity_reference-&gt;value(); //error here
    $b = $nodew-&gt;field_taxonomy_entity_reference-&gt;value();
    $c = array_unique(array_merge($a, $b));
    $filew-&gt;field_taxonomy_entity_reference = $c; //error here
    $filew-&gt;save();
  }
}
Sadly, I am posting a very bad workaround for future reference. Anybody who can improve this is welcome:

function mymodule_node_insert($node) {
  //copy terms
  $nodew = entity_metadata_wrapper('node', $node);
  //@todo this is not cool, figure it out
  foreach ($nodew-&gt;field_media-&gt;value() as $delta =&gt; $files) {
    $filew = entity_metadata_wrapper('file', $files['fid']);
    $filew-&gt;field_taxonomy_entity_reference = array_unique(array_merge($filew-&gt;field_taxonomy_entity_reference, $nodew-&gt;field_taxonomy_entity_reference));
    $filew-&gt;save();

  }
}