0

i am having this query :

   $db = \Drupal::database();

  $exist_query= $db->select('user__roles', 'ur');
  $exist_query->fields('ur', ['entity_id']);
  $exist_query->condition('ur.entity_id','u.uid', '=');
  $exist_query->condition('ur.roles_target_id', $included_user_roles, 'IN');

  $not_exist_query= $db->select('user__roles', 'ur');
  $not_exist_query->fields('ur', ['entity_id']);
  $not_exist_query->condition('ur.entity_id','u.uid', '=');
  $not_exist_query->condition('ur.roles_target_id', $excluded_user_roles, 'IN');

  $query = $db->select('users_field_data', 'u');
  $query->fields('u', ['uid']);
  $query->condition('u.uid', 1, '>');
  if (!empty($param['login_value'])) {
    $query->condition('u.login', $logindate, '<');
    $query->condition('u.login', 0, '!=');
  }  
  $query->exists($exist_query);
  $query->notExists($not_exist_query);
  dpq($query);

the problem i am having is here

  $exist_query->condition('ur.entity_id','u.uid', '=');

it generates :

WHERE (ur.entity_id = 'u.uid')

when it should

WHERE (ur.entity_id = u.uid)

How can i solve this ?

The working request i am trying to achieve

SELECT u.uid AS uid
FROM
users_field_data u
WHERE (u.uid > '1') AND (u.login < '1586705658') AND (u.login != '0') AND (EXISTS (SELECT ur.entity_id AS entity_id
FROM
user__roles ur
WHERE (ur.entity_id = u.uid) AND (ur.roles_target_id IN ('admin_site')))) AND (NOT EXISTS (SELECT ur.entity_id AS entity_id
FROM
user__roles ur
WHERE (ur.entity_id = u.uid) AND (ur.roles_target_id IN ('membre_du_site'))))
1

You can add such a clause manually:

$not_exist_query->where('ur.entity_id = u.uid');
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.