Get a rewrite of a query using Querybuilder API

Hello.

I'm trying to rewrite the code for Elgg 3. 

The code on Elgg 2 is:

$guid = elgg_get_logged_in_user_guid();

$options = [
  'type' => 'user',
  'limit' => 10,
  'joins' => "JOIN {$dbprefix}entity_relationships er ON er.guid_one = $guid
              AND er.relationship = 'member'",
  'wheres' => "er.guid_two IN (SELECT guid_two FROM {$dbprefix}entity_relationships
              WHERE guid_one = e.guid
              AND relationship = 'member')",
];

return elgg_get_entities($options);
 
I'm trying to get this working on Elgg 3:
 
$alias = 'er';
$guid = elgg_get_logged_in_user_guid();
$relationship = 'member';

$options = [
  'types' => 'user',
  'limit' => 10,
];

$options['wheres'][] = function(QueryBuilder $qb, $table_alias) use ($alias, $guid, $relationship) {
  $joins = [];
  $joins[] = $qb->compare("$alias.guid_one", '=', $guid, ELGG_VALUE_GUID);
  $joins[] = $qb->compare("$alias.relationship", '=', $relationship, ELGG_VALUE_STRING);

  $qb->join($table_alias, 'entity_relationships', $alias, $qb->merge($joins));

  $sub = $qb->subquery('entity_relationships', $alias);
  $sub->select('guid_two')
    ->where($qb->compare('guid_one', '=', "$table_alias.guid", ELGG_VALUE_GUID))
    ->andWhere($qb->compare('relationship', '=', $relationship, ELGG_VALUE_STRING));

  //return $qb->compare("$alias.guid_two", 'IN', $sub->getSQL());
  return $qb->where($qb->compare("$alias.guid_two", 'IN', $sub->getSQL()));

};


var_dump(elgg_get_entities($options));
 
Returns false.
 
Can you help with it?
 
Thank you very much!