I have a content type student, and it has an Entity Reference field named as field_offline_course_reference
and a email field field_offline_course_student_ema
I need a list of all emails of students based on field_offline_course_reference
value.
How can I change the following code to achieve what I want to do?
$courseinfo = $theCourseId;
$query = db_select('node', 'n');
$query->join("field_data_field_offline_course_reference", "t", "t.entity_id = n.nid");
$query->fields("n", array("nid"))
->condition('n.type', 'students')
->condition('t.entity_id', $courseinfo);
$result = $query->execute();
foreach ($result as $record) {
var_dump($result);
}