function relation_query_enforce_distinct_endpoints_alter in Relation 7
Same name and namespace in other branches
- 8.2 relation.module \relation_query_enforce_distinct_endpoints_alter()
- 8 relation.module \relation_query_enforce_distinct_endpoints_alter()
Implements hook_query_TAG_alter().
Adds conditions to query to ensure different r_index for each endpoint.
File
- ./
relation.module, line 557 - Describes relations between entities.
Code
function relation_query_enforce_distinct_endpoints_alter(QueryAlterableInterface $query) {
// Get arity of the query
$relation_query = $query
->getMetaData('entity_field_query');
foreach ($relation_query->propertyConditions as $condition) {
if ($condition['column'] == 'arity') {
$arity = $condition['value'];
break;
}
}
// Add r_index conditions between all endpoints
for ($i = 0; $i < $arity; $i++) {
for ($k = $i + 1; $k < $arity; $k++) {
$column_left = 'field_data_endpoints_delta_' . $i . '.endpoints_r_index';
$column_right = 'field_data_endpoints_delta_' . $k . '.endpoints_r_index';
$query
->where("{$column_left} != {$column_right}");
}
}
}