I set up a directional relation between users and nodes. I made a users view that needs to filter by a date filter on the relation. I added a user->relation relationship and was able to add the date field filter. However the view did not return the expected results. After a good while inspecting the views query, I determined that two joins are incorrect:
LEFT JOIN {field_data_endpoints} field_data_endpoints3 ON users.uid = field_data_endpoints3.entity_id AND (field_data_endpoints3.bundle = 'has_member' AND field_data_endpoints3.endpoints_r_index = '1')
LEFT JOIN {relation} relation_users ON field_data_endpoints3.endpoints_entity_id = relation_users.rid AND field_data_endpoints3.endpoints_entity_type = 'user'
these should be:
LEFT JOIN {field_data_endpoints} field_data_endpoints3 ON users.uid = field_data_endpoints3.endpoints_entity_id AND (field_data_endpoints3.bundle = 'has_member' AND field_data_endpoints3.endpoints_r_index = '1')
LEFT JOIN {relation} relation_users ON field_data_endpoints3.entity_id = relation_users.rid AND field_data_endpoints3.endpoints_entity_type = 'user'
Not being real sure how to modify relation_handler_relationship (in relation_handler_relationship.inc), I worked around this using a hook_views_query_alter, as follows:
function edg_misc_views_query_alter(&$view, &$query) {
//fix faulty relation table joins
// dpm($query->table_queue);
if($view->name == 'shop_students' && $view->current_display == 'entityreference_1') {
$query->table_queue['field_data_endpoints3']['join']->field = 'endpoints_entity_id';
$query->table_queue['relation_users']['join']->left_field = 'entity_id';
}
}I think I see where I can change the 'relation_users' left field (line 92?), but I don't see immediately see where the 'field_data_endpoints3' field name comes from, and in any case without thoroughly understanding what's going on, I hesitate to change anything!
Thanks.
Comments
Comment #1
Gaelan commentedDuplicate of #1780424: Views Relationship: Relation->Source(Directional) .