I am using db_select
to query the database to get some fields, one of the fields is a node reference and I don't know how to select it or join its table.
My content type contains a node reference, and this node reference contains another node reference (nested relationship), how can I from the original content type get the first node reference fields and the fields of its node reference ?
My current query :
$query = db_select("node", "n");
$query->fields("n", array("nid", "created", "type"));
$query->fields("f1", array('field_field1_value'));
$query->fields("f2", array('field_field2_value'));
$query->leftJoin('field_data_field_field1', 'f1', 'f1.entity_id = n.nid');
$query->leftJoin('field_data_field_field2', 'f2', 'f2.entity_id = n.nid');
$query->condition('n.type', 'my_content_type', '=');
$query = $query->orderBy('n.created', 'DESC');
$query = $query->extend('TableSort')->extend('PagerDefault')->limit(20);
$result = $query->execute();