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.67 -r1.67.2.1
--- openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	27 Jul 2015 12:52:58 -0000	1.67
+++ openacs-4/packages/acs-kernel/sql/postgresql/acs-objects-create.sql	12 Feb 2016 07:56:48 -0000	1.67.2.1
@@ -235,8 +235,9 @@
 				references acs_object_types (object_type),
         title			varchar(1000) default null,
         package_id		integer default null,
-        context_id		integer constraint acs_objects_context_id_fk
-				references acs_objects(object_id),
+        context_id		integer
+				CONSTRAINT acs_objects_context_id_fk
+				REFERENCES acs_objects(object_id) ON DELETE CASCADE,
 	security_inherit_p	boolean default 't' not null,
 	creation_user		integer,
 	creation_date		timestamptz default current_timestamp not null,
@@ -331,11 +332,11 @@
 
 create table acs_object_context_index (
 	object_id	integer not null
-                        constraint acs_obj_context_idx_obj_id_fk
-			references acs_objects(object_id),
+			CONSTRAINT acs_obj_context_idx_obj_id_fk
+			REFERENCES acs_objects(object_id) ON DELETE CASCADE,
 	ancestor_id	integer not null
-                        constraint acs_obj_context_idx_anc_id_fk
-			references acs_objects(object_id),
+			CONSTRAINT acs_obj_context_idx_anc_id_fk
+			REFERENCES acs_objects(object_id) ON DELETE CASCADE,
 	n_generations	integer not null
 			constraint acs_obj_context_idx_n_gen_ck
 			check (n_generations >= 0),
@@ -477,19 +478,6 @@
 create trigger acs_objects_context_id_up_tr after update on acs_objects
 for each row execute procedure acs_objects_context_id_up_tr ();
 
-CREATE OR REPLACE FUNCTION acs_objects_context_id_del_tr () RETURNS trigger AS $$
-BEGIN
-  delete from acs_object_context_index
-  where object_id = old.object_id;
-
-  return old;
-
-END;
-$$ LANGUAGE plpgsql;
-
-create trigger acs_objects_context_id_del_tr before delete on acs_objects
-for each row execute procedure acs_objects_context_id_del_tr ();
-
 ----------------------
 -- ATTRIBUTE VALUES --
 ----------------------
