Index: openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql,v
diff -u -r1.65 -r1.66
--- openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	27 Oct 2014 16:39:35 -0000	1.65
+++ openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	2 May 2015 16:47:50 -0000	1.66
@@ -938,40 +938,29 @@
 
 select define_function_args('acs_object__delete','object_id');
 
-
-
 --
 -- procedure acs_object__delete/1
 --
 CREATE OR REPLACE FUNCTION acs_object__delete(
    delete__object_id integer
 ) RETURNS integer AS $$
 DECLARE
-  obj_type                       record;
+  obj_type record;
 BEGIN
   
-  -- Delete dynamic/generic attributes
-  delete from acs_attribute_values where object_id = delete__object_id;
+  -- GN: the following deletion operation iterates over the id_columns
+  -- of the acs_object_types of the type tree for the obejct and
+  -- performs manual deletions in these tables by trying to delete the
+  -- delete__object_id from the id_column.  This deletion includes as
+  -- well the deletion in acs_objects.
+  --
+  -- In the best of all possible worlds, this would not
+  -- be necessary, when the objects would have specified "on delete
+  -- cascade" for the id_columns.
 
-  -- Delete direct permissions records.
-  delete from acs_permissions 
-  where object_id = delete__object_id
-    or  grantee_id = delete__object_id;
-
-  -- select table_name, id_column
-  --  from acs_object_types
-  --  start with object_type = (select object_type
-  --                              from acs_objects o
-  --                             where o.object_id = delete__object_id)
-  --  connect by object_type = prior supertype
-
-  -- There was a gratuitous join against the objects table here,
-  -- probably a leftover from when this was a join, and not a subquery.
-  -- Functionally, this was working, but time taken was O(n) where n is the 
-  -- number of objects. OUCH. Fixed. (ben)
   for obj_type
   in select o2.table_name, o2.id_column
-        from acs_object_types o1, acs_object_types o2
+       from acs_object_types o1, acs_object_types o2
        where o1.object_type = (select object_type
                                from acs_objects o
                                where o.object_id = delete__object_id)
@@ -984,9 +973,10 @@
     -- because the table names appear to be stored in upper case.  Quoting
     -- causes them to not match the actual lower or potentially mixed-case
     -- table names.  We will just forbid squirrely names that include quotes.
--- daveB
--- ETP is creating a new object, but not a table, although it does specify a
--- table name, so we need to check if the table exists. Wp-slim does this too
+    
+    -- daveB
+    -- ETP is creating a new object, but not a table, although it does specify a
+    -- table name, so we need to check if the table exists. Wp-slim does this too
 
     if table_exists(obj_type.table_name) then
       execute 'delete from ' || obj_type.table_name ||
