--
-- notification_request__delete/1
--
create or replace function notification_request__delete(
  integer
) returns int4 as $$

declare
    p_request_id                    alias for $1;
    v_notifications record;
begin
    for v_notifications in select notification_id
                           from notifications n, notification_requests nr
                           where n.response_id = nr.object_id
                             and nr.request_id = p_request_id
    loop
      perform acs_object__delete(v_notifications.notification_id);
    end loop;

    perform acs_object__delete(p_request_id);
    return 0;
end;
$$ language plpgsql;