View with relationship to custom entity via computed property View with relationship to custom entity via computed property

I have nodes connected to a custom entity (called here "myentity") via a computed property, like this:

  $info['node']['properties']['myentity'] = array(
    'label' =&gt; t("Myentity"),
    'type' =&gt; 'myentity',
    'computed' =&gt; TRUE,
    'queryable' =&gt; TRUE,  // setting this to FALSE doesn't change anything
    'entity views field' =&gt; TRUE,
    'getter callback' =&gt; 'mymodule_node_property_myentity_get',
  );


The callback function extracts some values from the node and calls another function, which fills these values into an entity field query, returning the wanted myentity instance.

This entity connection is working, so I can get the property "myprop" of myentity via an entity API wrapper $node_wrapper-&gt;myentity-&gt;myprop-&gt;value().

Now I want to add myprop in a simple view for nodes. After creating a relationship to myentity, "Content: Myentity" shows up in the "Add fields" list, as well as all of myentity's properties.

Selecting "Content: Myentity" works - myentity's default label is displayed in the view output. (With some magic - the displayed SQL query is SELECT node.nid AS nid FROM {node} node).

However, selecting "Myentity: Myprop" does not work. Even before executing the view, Drupal shows a SQL error:

SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "myentity" LINE 1: SELECT node.nid AS nid, myentity.myprop AS myentity_myprop, no... ^


The displayed SQL query here is SELECT node.nid AS nid, myentity.myprop AS myentity_myprop FROM {node} node. myentity is referenced in the select clause, but not in the from clause, nor is there any join statement. 

Has somebody managed to add properties of a custom entity, connected via a computed node property, to views?
Finally figured out a workaround: Pull every needed entity property as a "virtual field" into the node itself.

// define additional property information for node
function mymodule_entity_property_info_alter(&amp;$info) {
  $properties = &amp; $info['node']['properties'];
  foreach (array('myprop') as $property) {
    $properties[$property] = array(
      'label' =&gt; $info['mymodule']['properties'][$property]['label'],
      'description' =&gt; $info['mymodule']['properties'][$property]['description'],
      'type' =&gt; $info['mymodule']['properties'][$property]['type'],
      'computed' =&gt; TRUE,
      'queryable' =&gt; TRUE,
      'entity views field' =&gt; TRUE,
      'getter callback' =&gt; "mymodule_node_property_verbatim_get",
    );
  }
}

// getter callback
function mymodule_node_property_verbatim_get($data, array $options, $name, $type, $info) {
  $myentity = mymodule_get_from_node($data);
  return !empty($publication-&gt;{$name}) ? $publication-&gt;{$name} : array();
}

// obtain the related entity from the node
function mymodule_get_from_node($node) {

  // some custom code to get myentity

  return $myentity;
}


Thus, the properties can be adressed as views fields as well as for any other purposes. It's possible to extend this to access properties of nested entities, too. 

One drawback, however: The fields cannot be used as views sort criteria.