# HG changeset patch # User jbe # Date 1257591600 -3600 # Node ID d45919d791ff96c6f92fdd3bc6de47a4bba0a47d # Parent 23092eb00e16dad8a7deec95c494fad74381cb10 Version beta3 Minor bugfix: Autocreated entries in supporter table refer to the current draft of the initiative instead of throwing an error diff -r 23092eb00e16 -r d45919d791ff core.sql --- a/core.sql Tue Nov 03 12:00:00 2009 +0100 +++ b/core.sql Sat Nov 07 12:00:00 2009 +0100 @@ -259,7 +259,7 @@ COMMENT ON TABLE "supporter" IS 'Members who support an initiative (conditionally)'; -COMMENT ON COLUMN "supporter"."draft_id" IS 'Latest seen draft'; +COMMENT ON COLUMN "supporter"."draft_id" IS 'Latest seen draft, defaults to current draft of the initiative (implemented by trigger "default_for_draft_id")'; CREATE TABLE "opinion" ( @@ -676,6 +676,25 @@ COMMENT ON TRIGGER "copy_autoreject" ON "interest" IS 'If "autoreject" is NULL, then copy it from the area setting, or set to FALSE, if no membership existent'; +CREATE FUNCTION "supporter_default_for_draft_id_trigger"() + RETURNS TRIGGER + LANGUAGE 'plpgsql' VOLATILE AS $$ + BEGIN + IF NEW."draft_id" ISNULL THEN + SELECT "id" INTO NEW."draft_id" FROM "current_draft" + WHERE "initiative_id" = NEW."initiative_id"; + END IF; + RETURN NEW; + END; + $$; + +CREATE TRIGGER "default_for_draft_id" BEFORE INSERT OR UPDATE ON "supporter" + FOR EACH ROW EXECUTE PROCEDURE "supporter_default_for_draft_id_trigger"(); + +COMMENT ON FUNCTION "supporter_default_for_draft_id_trigger"() IS 'Implementation of trigger "default_for_draft" on table "supporter"'; +COMMENT ON TRIGGER "default_for_draft_id" ON "supporter" IS 'If "draft_id" is NULL, then use the current draft of the initiative as default'; + + ---------------------------------------- -- Automatic creation of dependencies --