i want a vitual field for print value of sum in another entity :
My 2 custom entity content :
commandes_entity
commandesLignes_entity reference to commandes_entity
In the commandes_entity i have a view table who liste all my lines. i want to add a custom column who sum all the children in commandesLignes_entity.
For that i make a field in .module :
function hook_views_data()
{
$data['commandes_entity'] = array(
'totalCommandeTTC' => array(
'title' => t('Total Commande TTC'),
'help' => t("Le total des commandes"),
'field' => array(
'id' => 'machine_name',
'options callback' => 'Drupal\boutique\Controller\TestController::content',
),
'sort' => array(
'id' => 'standard',
),
),
);
return $data;
}
This field is in my select field view, when i add it all is ok except one thing :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'commandes_entity.totalCommandeTTC' in 'field list': SELECT commandes_entity.totalCommandeTTC AS commandes_entity_totalcommandettc, commandes_entity.id AS id FROM {commandes_entity} commandes_entity WHERE (( (commandes_entity.statut LIKE :db_condition_placeholder_0 ESCAPE '\') )) ORDER BY commandes_entity.created DESC LIMIT 21 OFFSET 0; Array ( [:db_condition_placeholder_0] => payer )
This field
totalCommandeTTC
doesn't exist in my table, i want it virtual.
For now my callback just return 'test'.
Any idea for make this field really virtual ?
I try to move it to views group like this :
function boutique_views_data()
{
$data['views'] = array(
'totalCommandeTTC' => array(
'title' => t('Total Commande TTC'),
'help' => t("Le total des commandes"),
'field' => array(
'id' => 'machine_name',
'options callback' => 'Drupal\boutique\Controller\TestController::content',
),
'sort' => array(
'id' => 'standard',
),
),
);
return $data;
}
The field is in the Global group but SQL still try to get it into the commandes_entity table.