I have created a custom entity with several properties and several attached fields.
When I load a instance of my custom entity, update a property of the entity (e.g UID) and save it a new revision of the entity is created, but also a new revision of every attached field is created.
To avoid saving lots of redundant data I only really want to create a new revision of an attached field if the data in that field has changed.
I've noticed that this same behavior is exhibited by core node objects, but is still not really desirable.
My function which currently saves my entity looks like this:
/**
* Saves a emtr safe check to the database.
*
* @param $emtr_safe_check
* The emtr_safe_check object.
*/
function emtr_safe_check_save(EMTRSafeCheck $emtr_safe_check) {
$is_new = isset($emtr_safe_check->is_new) ? $emtr_safe_check->is_new : false;
// always make a new revision
$emtr_safe_check->is_new_revision = TRUE;
$emtr_safe_check->save();
if($is_new) {
// now we have the new emtr safe check id lets save the attached fields
field_attach_insert('emtr_safe_check', $emtr_safe_check);
} else {
// This is where my attached fields are saved
// Can I do something clever here to avoid creating redundant revisions?
field_attach_update('emtr_safe_check', $emtr_safe_check);
}
return $emtr_safe_check;
}