Skip to main content
1 of 2
4uk4
  • 101.7k
  • 7
  • 173
  • 217

The main property of a reference field in D8 is still the target id:

$node->field_code_used_by->target_id = $user_id;

The entity property is a computed value. If you put an object in this value, drupal will convert it back to the id before saving it to the dababase.

4uk4
  • 101.7k
  • 7
  • 173
  • 217