I am creating an entity via code and I want to set one of the fields that is an entity reference to a single entity to be null or some empty value.
Can you tell me what I should pass into the set method please?

Extract from my code:
$values = array(
'type' => 'booking',
'uid' => $uid,
'status' => 1,
'comment' => 1,
'promote' => 0,
'title' => INITIAL_BOOKING_TITLE,
'language' => 'und',
);
$entity = entity_create('node', $values);
$ewrapper = entity_metadata_wrapper('node', $entity);
$ewrapper->field_book_property->set(null); // this is a single entity ref field and an exception is thrown when its called
$ewrapper->save();

I want to do this as I am experiencing a few issues with the language of my fields and if I set each field to a default value when the entity is created then all of the field language values are 'und' which is what I want.

If I don't call ->set on some of my fields prior to the initial save, then in some scenarios (I am not too sure exactly what) some of the unset fields have an 'en' entry created in the field and then if I set the value via code at a later date and then call ->save an 'und' entry is also added.
This means I end up with two entries which cause issues elsewhere. I only want a single 'und' entry per field.

Side note: I was using locale and i18n when I first started this work, but I have subsequently uninstalled them, so I have no idea why the 'en' entry is created.

Many thanks.

Comments

gony created an issue. See original summary.

gony’s picture

Issue summary: View changes