--
-- cr_type_template_map_tr/0
--
create or replace function cr_type_template_map_tr(
  
) returns trigger as $$

begin

  if new.is_default = 't' then
    update
      cr_type_template_map
    set
      is_default = 'f'
    where
      content_type = new.content_type
    and
      use_context = new.use_context
    and 
      template_id <> new.template_id
    and
      is_default = 't';
  end if;

  return new;

end;$$ language plpgsql;