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' => t("Myentity"),
'type' => 'myentity',
'computed' => TRUE,
'queryable' => TRUE, // setting this to FALSE doesn't change anything
'entity views field' => TRUE,
'getter callback' => '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->myentity->myprop->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?