I know I can update (or set a value for) an entity reference field in Drupal 7 with code similar to the following.
$node['field_code_used_by'][LANGUAGE_NONE]['target_id'] = $id;
I want to programmatically set a value for my user entity reference field in Drupal 8.
I tried with
$node->field_code_used_by->entity->value = 1; but neither of them worked.
How can I set the value for an entity reference field?