0

Delete query is called while updating the cck field value of node.

After debugging i find following code in

var/www/drupal-7.40/modules/field/modules/field_sql_storage/field_sql_storage.module

in field_sql_storage_field_storage_write($entity_type, $entity, $op, $fields)

we have following code

// Delete and insert, rather than update, in case a value was added.
if ($op == FIELD_STORAGE_UPDATE) {
  // Delete languages present in the incoming $entity->$field_name.
  // Delete all languages if $entity->$field_name is empty.
  $languages = !empty($entity->$field_name) ? $field_languages : $all_languages;
  if ($languages) {
    db_delete($table_name)
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $id)
      ->condition('language', $languages, 'IN')
      ->execute();
    db_delete($revision_name)
      ->condition('entity_type', $entity_type)
      ->condition('entity_id', $id)
      ->condition('revision_id', $vid)
      ->condition('language', $languages, 'IN')
      ->execute();
  }
}

May be someone explain why ? And also can i use update Query instead of delete, insert ?

  • calling? you mean called? – GwenM Feb 8 '16 at 13:17
  • Yes while i am editing any node and trying to save, delete query is called for cck fields ex: "field_data_body" – visabhishek Feb 8 '16 at 13:37
1

As the comment at the top states: Delete and insert, rather than update, in case a value was added.

So to make sure all old data is cleared, the records are deleted and re-added with new data (as you can see on line 481: $query = db_insert($table_name)->fields($columns);.

Of course you could use the update query, but this query would need to contain all fields because it is impossible to know which fields are added, modified or deleted. A simple delete and add solves that problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.