From 52ff3b7c57f6f0bf1e86a492c31cb5ee270fef93 Mon Sep 17 00:00:00 2001
From: Chad Fennell <libsys@gmail.com>
Date: Mon, 28 Feb 2011 20:32:28 -0600
Subject: [PATCH] Issue #1064394 only call entity_delete_multiple for on field collection with ids

---
 field_collection.module |    8 ++++++--
 field_collection.test   |    7 ++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/field_collection.module b/field_collection.module
index 2c92318..314207f 100644
--- a/field_collection.module
+++ b/field_collection.module
@@ -506,8 +506,12 @@ function field_collection_field_presave($entity_type, $entity, $field, $instance
  * Implements hook_field_delete().
  */
 function field_collection_field_delete($entity_type, $entity, $field, $instance, $langcode, &$items) {
-  // Also delete all embedded entities.
-  entity_delete_multiple('field_collection_item', field_collection_field_item_to_ids($items));
+  $ids = field_collection_field_item_to_ids($items);
+  //Don't try to delete empty collection items
+  if (!empty($ids)) {
+    // Also delete all embedded entities.
+    entity_delete_multiple('field_collection_item', $ids);
+  }
 }
 
 /**
diff --git a/field_collection.test b/field_collection.test
index f2db519..cce3318 100644
--- a/field_collection.test
+++ b/field_collection.test
@@ -48,7 +48,12 @@ class FieldCollectionBasicTestCase extends DrupalWebTestCase {
    * Tests CRUD.
    */
   function testCRUD() {
-    $node = $this->drupalCreateNode(array('type' => 'article'));
+    $node = $this->drupalCreateNode(array('type' => 'article'));    
+    // Make sure nodes with collection fields without values are deleted.
+    node_delete($node->nid);
+    $this->assertTrue(node_load($node->nid, NULL, TRUE) == FALSE, 'nodes without field_collections are deleted.');
+
+    $node = $this->drupalCreateNode(array('type' => 'article'));    
     // Manually create a field_collection.
     $entity = entity_create('field_collection_item', array('field_name' => $this->field_name));
     $entity->setHostEntity('node', $node);
-- 
1.7.2.1

