Skip to main content
added 1 character in body
Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

Sounds like you should be setting target_id instead:

foreach ($nameResult as $row) {
  $node->field_co_pi[LANGUAGE_NONE][$i]['target_id'] = intval($row->entity_id);
}

Note that not all fields have the same data column (such as 'value'). Reference fields have target_id which holds the referenced entity id.

Aside from that, just make sure that it has a value before setting, or you will get the same error again.

You redacted other parts of the code, so, I can't see if you set $i or not. Are you incrementing that per loop with $i++? I just assumed it is a multivalued field since you are doing a foreach instead of setting [0] directly.

Sounds like you should be setting target_id instead:

foreach($nameResult as $row) {
  $node->field_co_pi[LANGUAGE_NONE][$i]['target_id'] = intval($row->entity_id);
}

Note that not all fields have the same data column (such as 'value'). Reference fields have target_id which holds the referenced entity id.

Aside from that, just make sure that it has a value before setting, or you will get the same error again.

You redacted other parts of the code, so, I can't see if you set $i or not. Are you incrementing that per loop with $i++? I just assumed it is a multivalued field since you are doing a foreach instead of setting [0] directly.

Sounds like you should be setting target_id instead:

foreach ($nameResult as $row) {
  $node->field_co_pi[LANGUAGE_NONE][$i]['target_id'] = intval($row->entity_id);
}

Note that not all fields have the same data column (such as 'value'). Reference fields have target_id which holds the referenced entity id.

Aside from that, just make sure that it has a value before setting, or you will get the same error again.

You redacted other parts of the code, so, I can't see if you set $i or not. Are you incrementing that per loop with $i++? I just assumed it is a multivalued field since you are doing a foreach instead of setting [0] directly.

Source Link
Kevin
  • 28k
  • 12
  • 95
  • 196

Sounds like you should be setting target_id instead:

foreach($nameResult as $row) {
  $node->field_co_pi[LANGUAGE_NONE][$i]['target_id'] = intval($row->entity_id);
}

Note that not all fields have the same data column (such as 'value'). Reference fields have target_id which holds the referenced entity id.

Aside from that, just make sure that it has a value before setting, or you will get the same error again.

You redacted other parts of the code, so, I can't see if you set $i or not. Are you incrementing that per loop with $i++? I just assumed it is a multivalued field since you are doing a foreach instead of setting [0] directly.