How do you achieve the highlighted 'node' alias when using the Drupal 7 database abstraction language?
This is the original query produced by the view
SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, **'node' AS field_data_field_reference_code_node_entity_type, 'node' AS field_data_field_employer_node_entity_type, 'node' AS field_data_field_contract_type_node_entity_type, 'node' AS field_data_field_display_location_node_entity_type, 'node' AS field_data_field_salary_description_node_entity_type**
FROM
{node} node
INNER JOIN {field_data_field_locations} field_data_field_locations ON node.nid = field_data_field_locations.entity_id AND (field_data_field_locations.entity_type = 'node' AND field_data_field_locations.deleted = '0')
LEFT JOIN {workflow_node_history} workflow_node_current ON ( SELECT max(hid) FROM {workflow_node_history} where nid = node.nid and sid != old_sid ) = workflow_node_current.hid
WHERE (( (node.type IN ('job')) AND (field_data_field_locations.field_locations_tid = '56') AND (workflow_node_current.sid = '3') ))
ORDER BY node_created DESC
LIMIT 10 OFFSET 0;
Here my current code, which produces the query but cant recreate the aliases in bold with the addfield method. Tried to escape the quotes around 'node' but drupal stripes it out.
$result = db_select('node','node');
$join = $result->innerJoin('field_data_field_locations','field_data_field_locations',"node.nid = field_data_field_locations.entity_id AND field_data_field_locations.entity_type = 'node' AND field_data_field_locations.deleted = '0'");
$result->leftJoin('workflow_node_history','workflow_node_current',"(SELECT max(hid) FROM {workflow_node_history} where nid = node.nid and sid != old_sid ) = workflow_node_current.hid");
$result->addField('','node')
$result->addField('node','title','node_title');
$result->addField('node','created','node_created');
$result->addField('node','nid','nid');
$result->condition('node.type',array('job'),'IN');
$result->condition('field_data_field_locations.field_locations_tid','56','=');
$result->condition('workflow_node_current.sid','3','=');
$result->orderby('node.created','desc');
FROM
,JOIN
and so on. It seems you can use aliases all right, so I don't know what's exactly your problem here. – Mołot Jul 7 '14 at 9:40