Index: openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql,v
diff -u -r1.35.2.3 -r1.35.2.4
--- openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql	7 Jul 2016 06:12:46 -0000	1.35.2.3
+++ openacs-4/packages/acs-kernel/sql/postgresql/groups-body-create.sql	31 Aug 2016 18:57:41 -0000	1.35.2.4
@@ -32,12 +32,12 @@
 -- procedure membership_rels_in_tr/0
 --
 CREATE OR REPLACE FUNCTION membership_rels_in_tr(
-
 ) RETURNS trigger AS $$
 DECLARE
   v_object_id_one acs_rels.object_id_one%TYPE;
   v_object_id_two acs_rels.object_id_two%TYPE;
   v_rel_type      acs_rels.rel_type%TYPE;
+  v_composable_p  acs_rel_types.composable_p%TYPE;
   v_error         text;
   map             record;
 BEGIN
@@ -48,9 +48,10 @@
       raise EXCEPTION '-20000: %', v_error;
   end if;
 
-  select object_id_one, object_id_two, rel_type
-  into v_object_id_one, v_object_id_two, v_rel_type
-  from acs_rels
+  select object_id_one, object_id_two, r.rel_type, composable_p
+  into v_object_id_one, v_object_id_two, v_rel_type, v_composable_p
+  from acs_rels r
+  join acs_rel_types t on (r.rel_type = t.rel_type)
   where rel_id = new.rel_id;
 
   -- Insert a row for me in the group_element_index.
@@ -65,26 +66,29 @@
     perform party_approved_member__add(v_object_id_one, v_object_id_two, new.rel_id, v_rel_type);
   end if;
 
-  -- For all groups of which I am a component, insert a
-  -- row in the group_element_index.
-  for map in select distinct group_id
+  -- If this rel_type composable...
+  if v_composable_p = 't' then
+
+     -- For all groups of which I am a component, insert a
+     -- row in the group_element_index.
+     for map in select distinct group_id
 	      from group_component_map
 	      where component_id = v_object_id_one 
-  loop
+     loop
 
-    insert into group_element_index
-     (group_id, element_id, rel_id, container_id,
-      rel_type, ancestor_rel_type)
-    values
-     (map.group_id, v_object_id_two, new.rel_id, v_object_id_one,
-      v_rel_type, 'membership_rel');
+        insert into group_element_index
+               (group_id, element_id, rel_id, container_id,
+               rel_type, ancestor_rel_type)
+        values
+               (map.group_id, v_object_id_two, new.rel_id, v_object_id_one,
+               v_rel_type, 'membership_rel');
 
-    if new.member_state = 'approved' then
-      perform party_approved_member__add(map.group_id, v_object_id_two, new.rel_id, v_rel_type);
-    end if;
+        if new.member_state = 'approved' then
+           perform party_approved_member__add(map.group_id, v_object_id_two, new.rel_id, v_rel_type);
+        end if;
 
-  end loop;
-
+     end loop;
+  end if;
   return new;
 
 END;
@@ -214,15 +218,17 @@
 		  and element_id = m.member_id
 		  and rel_id = m.rel_id);
 
-  -- Make my elements be elements of my new composite group
+  -- Make my composable elements be elements of my new composite group
   insert into group_element_index
    (group_id, element_id, rel_id, container_id,
     rel_type, ancestor_rel_type)
   select distinct
    v_object_id_one, element_id, rel_id, container_id,
-   rel_type, ancestor_rel_type
+   m.rel_type, ancestor_rel_type
   from group_element_map m
+  join acs_rel_types t on (m.rel_type = t.rel_type)
   where group_id = v_object_id_two
+  and t.composable_p = 't'
   and not exists (select 1
 		  from group_element_map
 		  where group_id = v_object_id_one
@@ -247,25 +253,29 @@
 
     -- Add to party_approved_member_map
 
-    perform party_approved_member__add(map.group_id, member_id, rel_id, rel_type)
+    perform party_approved_member__add(map.group_id, member_id, rel_id, m.rel_type)
     from group_approved_member_map m
+    join acs_rel_types t on (m.rel_type = t.rel_type)
     where group_id = v_object_id_two
+    and t.composable_p = 't'
     and not exists (select 1
 		    from group_element_map
 		    where group_id = map.group_id
 		    and element_id = m.member_id
 		    and rel_id = m.rel_id);
 
-    -- Add rows for my elements
+    -- Add rows for my composable elements
 
     insert into group_element_index
      (group_id, element_id, rel_id, container_id,
       rel_type, ancestor_rel_type)
     select distinct
      map.group_id, element_id, rel_id, container_id,
-     rel_type, ancestor_rel_type
+     m.rel_type, ancestor_rel_type
     from group_element_map m
+    join acs_rel_types t on (m.rel_type = t.rel_type)
     where group_id = v_object_id_two
+    and t.composable_p = 't'
     and not exists (select 1
 		    from group_element_map
 		    where group_id = map.group_id
@@ -413,6 +423,7 @@
 DECLARE
   v_rel_id               integer;       
 BEGIN
+    raise NOTICE 'composition_rel__new one % two %', object_id_one, object_id_two;
     v_rel_id := acs_rel__new (
       new__rel_id,
       rel_type,
