Saving a single field of a node/entity

Sometimes doing a full node_save/entity_save on an entity is overkill, like when updating a single field's value and not needing anything else to change.

This can be achieved by doing part of the complete entity_save function - prepare, update, and flush caches.

$entity = booking_load($booking_id);
$entity->field_fieldname[LANGUAGE_NONE][0]['value'] = 'new value';
field_attach_presave('booking', $entity);
field_attach_update('booking', $entity);
entity_get_controller('booking')->resetCache(array($entity->id));

This will update all of the fields on the $entity, which is probably more than is wanted. It can be reduced down to only the field that is needed.

$entity = new stdClass();
$entity->id = $booking_id;
$entity->bundle = $bundle_id;
$entity->field_fieldname[LANGUAGE_NONE][0]['value'] = 'new value';
field_attach_presave('booking', $entity);
field_attach_update('booking', $entity);
entity_get_controller('booking')->resetCache(array($entity->id));

NB: This will bypass most security limitations, and stuff up revisions. Use with care.