Store entity with entity reference field? I want to create an ECK programmatically, I can create it but the issue is with the entity reference fields that being empty 

The interesting issue is that when I try to edit the created entity, just some fields are accessible none of entity references.

The more interesting issue is when I try to see the list of that entity page is broken and show this error to me.


  Error: Call to a member function label() on null in Drupal\eck\Controller\EckEntityListBuilder->buildRow() (line 43 of modules\contrib\eck\src\Controller\EckEntityListBuilder.php).


I tried these codes:

  // Define entity type and bundle.
  $entity_type = "attendees";
  $bundle = "attendees";

  // Get definition of target entity type.
  $entity_definition = \Drupal::service('entity.manager')-&gt;getDefinition($entity_type);
  // Load up an array for creation.
  var_dump($entity_definition);
//  die();
  $entity_data = [
    'title' =&gt; 'this is test new',
//    'field_address' =&gt; $studentRecord['field_address'],
    'field_student_account' =&gt; 10,
    'field_students' =&gt; 48,
    'field_enrollment' =&gt; 270,
    'field_status' =&gt; 'Active',
//    'field_description' =&gt; "tsetestsetstes",
     // Use entity definition to set the appropriate property for the bundle.
    $entity_definition-&gt;getKeys()['bundle'] =&gt; $bundle,
  ];
  $new_entity = \Drupal::service('entity.manager')-&gt;getStorage($entity_type)-&gt;create($entity_data);
  $new_entity-&gt;save();
  var_dump($new_entity-&gt;id());
  die();


here are the valid values for another that created from the front end.

#values: array:12 [▼
    "id" =&gt; array:1 [▼
      "x-default" =&gt; "15"
    ]
    "type" =&gt; array:1 [▼
      "x-default" =&gt; "attendance"
    ]
    "uuid" =&gt; array:1 [▼
      "x-default" =&gt; "9a1fd3ec-3d7d-4926-a1d2-fcafc8fce3c2"
    ]
    "langcode" =&gt; array:1 [▼
      "x-default" =&gt; "en"
    ]
    "title" =&gt; array:1 [▼
      "x-default" =&gt; "group lesson"
    ]
    "created" =&gt; array:1 [▼
      "x-default" =&gt; "1561802666"
    ]
    "changed" =&gt; array:1 [▼
      "x-default" =&gt; "1561802705"
    ]
    "default_langcode" =&gt; array:1 [▼
      "x-default" =&gt; "1"
    ]
    "field_enrollment" =&gt; array:1 [▼
      "x-default" =&gt; array:1 [▼
        0 =&gt; array:1 [▼
          "target_id" =&gt; "271"
        ]
      ]
    ]
    "field_status" =&gt; array:1 [▼
      "x-default" =&gt; array:1 [▼
        0 =&gt; array:1 [▼
          "value" =&gt; "Inactive"
        ]
      ]
    ]
    "field_students" =&gt; array:1 [▼
      "x-default" =&gt; array:1 [▼
        0 =&gt; array:1 [▼
          "target_id" =&gt; "69"
        ]
      ]
    ]
    "field_student_account" =&gt; array:1 [▼
      "x-default" =&gt; array:1 [▼
        0 =&gt; array:1 [▼
          "target_id" =&gt; "27"
        ]
      ]
    ]
  ]


And this is the data that comes with programmatically creation.

EckEntity {#1106 ▼
  #values: array:8 [▼
    "id" =&gt; array:1 [▼
      "x-default" =&gt; "16"
    ]
    "type" =&gt; array:1 [▼
      "x-default" =&gt; "attendees"
    ]
    "uuid" =&gt; array:1 [▼
      "x-default" =&gt; "1048d24d-ffc7-4243-81c1-b26b5e9e9ecb"
    ]
    "langcode" =&gt; array:1 [▼
      "x-default" =&gt; "en"
    ]
    "title" =&gt; array:1 [▼
      "x-default" =&gt; "this is test new"
    ]
    "created" =&gt; array:1 [▼
      "x-default" =&gt; "1561806843"
    ]
    "changed" =&gt; array:1 [▼
      "x-default" =&gt; "1561806843"
    ]
    "default_langcode" =&gt; array:1 [▼
      "x-default" =&gt; "1"
    ]
  ]


this is my fields map


And this is the form display setting
You should try this for entity reference fields:
Single value:

$entity_data = [
'field_student_account' =&gt; ['target_id' =&gt; 10],
];


Multiple values:

$entity_data = [
'field_student_account' =&gt; [
    ['target_id' =&gt; 10],
    ['target_id' =&gt; 11],
  ],
];


Hope that works :)