I use this:
$values = array(
'type' => 'competition',
'title' => 'my title goes here',
);
$node = \Drupal::entityTypeManager()
->getStorage('node')
->create($values);
This works perfectly. But the problem is, I also have a node reference field called "field_competition_node_reference". But this doesnt work:
$values = array(
'type' => 'competition',
'title' => 'my title goes here',
'field_competition_node_reference' => 1,
);
How would one go about doing this? The value on the object is "target_id". Maybe that's why "create()" doesnt work?