Add query condition for referenced user by user ID I have created a content type with machine name user_points and let's say have the following fields for this content type:

nid,
title,
reference_id (text),
user (reference of user entity),
points (integer)


the following code give me the sum of all points.

$storage = $this-&gt;entityTypeManager()-&gt;getStorage('node'); 
    $total_points = $storage-&gt;getAggregateQuery()
      -&gt;condition('status', 1)
      -&gt;aggregate('points', 'SUM')
      -&gt;condition('type', 'user_points')
      -&gt;execute();


I would like to add a condition to get total points for specific referenced user by user ID. How can I do it?
if the machine name of user entity referenced in user_points content type is for example field_my_user, the following condition can be added to the query above to select only nodes with referenced user equal to $user_id

-&gt;condition('field_my_user.entity:user.uid', $user_id)