From 2dd6e7c0df25a8175f173fbc9a750bae31480647 Mon Sep 17 00:00:00 2001 From: "Karl O. Pinc kop@karlpinc.com" Date: Wed, 20 May 2026 15:12:04 +0000 Subject: [PATCH] The individual consuming the food must be the focal --- db/schemas/lib/triggers/create/follows.m4 | 40 +++++++++++++++++++ db/schemas/lib/triggers/create/roles.m4 | 47 +++++++++++++++++++++++ doc/src/tables/events.m4 | 6 +++ 3 files changed, 93 insertions(+) diff --git a/db/schemas/lib/triggers/create/follows.m4 b/db/schemas/lib/triggers/create/follows.m4 index c2449a5..5e59cf4 100644 --- a/db/schemas/lib/triggers/create/follows.m4 +++ b/db/schemas/lib/triggers/create/follows.m4 @@ -529,6 +529,46 @@ CREATE OR REPLACE FUNCTION follows_func () END; END IF; + IF TG_OP = 'UPDATE' + AND NEW.focal <> OLD.focal THEN + + -- The individual eating must be the focal. + SELECT events.eid, events.behavior, events.start, events.stop + , roles.pid, roles.role, roles.participant + INTO a_eid , a_behavior , a_start , a_stop + , a_pid , a_role , a_participant + FROM events + JOIN roles + ON (roles.eid = events.eid) + WHERE events.fid = NEW.fid + AND events.behavior = 'sdb_food' + AND roles.participant <> NEW.focal; + IF FOUND THEN + RAISE EXCEPTION integrity_constraint_violation USING + MESSAGE = 'Error on UPDATE of FOLLOWS' + , DETAIL = 'The individual eating must the the focal' + || ': Key (FID) = (' + || NEW.fid + || '), Value (Focal) = (' + || NEW.focal + || '), Value (Date) = (' + || NEW.date + || '): Key (EVENTS.EID) = (' + || a_eid + || '): Value (EVENTS.Behavior) = (' + || a_behavior + || '), Value (EVENTS.Start) = (' + || a_start + || '), Value (EVENTS.Stop) = (' + || a_stop + || '): Key (ROLES.PID) = (' + || a_pid + || '), Value (ROLES.Role) = (' + || a_role + || ')'; + END IF; + END IF; + RETURN NULL; END; $$; diff --git a/db/schemas/lib/triggers/create/roles.m4 b/db/schemas/lib/triggers/create/roles.m4 index 4fb22b3..d366252 100644 --- a/db/schemas/lib/triggers/create/roles.m4 +++ b/db/schemas/lib/triggers/create/roles.m4 @@ -333,6 +333,53 @@ CREATE OR REPLACE FUNCTION roles_func () END; END IF; + -- + -- The participant must be the focal for food events + -- + IF TG_OP = 'INSERT' + AND a_behavior = 'sdb_food' THEN + DECLARE + a_focal follows.focal%TYPE; + a_date follows.date%TYPE; + a_community follows.community%TYPE; + + BEGIN + SELECT follows.focal, follows.date, follows.community + INTO a_focal , a_date , a_community + FROM follows + WHERE follows.fid = a_fid + AND NEW.participant <> follows.focal; + IF FOUND THEN + RAISE EXCEPTION integrity_constraint_violation USING + MESSAGE = 'Error on INSERT of ROLES' + , DETAIL = 'The individual eating must be the focal' + || ': Key (PID) = (' + || NEW.pid + || '), Value (EID) = (' + || NEW.eid + || '), Value (Role) = (' + || NEW.role + || '), Value (Participant) = (' + || NEW.participant + || '), Value (EVENTS.Behavior) = (' + || a_behavior + || '), Value (EVENTS.Start) = (' + || a_start + || '), Value (EVENTS.Stop) = (' + || a_stop + || '), Value (FOLLOWS.FID) = (' + || a_fid + || '), Value (FOLLOWS.Focal) = (' + || a_focal + || '), Value (FOLLOWS.Date) = (' + || a_date + || '), Value (FOLLOWS.Community) = (' + || a_community + || ')'; + END IF; + END; + END IF; + -- -- Depending on the behavior, when there are multiple participants -- each must be distinct. diff --git a/doc/src/tables/events.m4 b/doc/src/tables/events.m4 index 781c0dc..fded63b 100644 --- a/doc/src/tables/events.m4 +++ b/doc/src/tables/events.m4 @@ -130,6 +130,12 @@ The following table lists these rules and implications: The system will generate a warning when there is no |ROLES| row related to the food event. + The individual consuming the food must be the the focal of the + follow. + This means that the |ROLES| row related to the event must have a + |ROLES|.\ |ROLES.Participant| value equal to the |FOLLOWS|.\ + |FOLLOWS.Focal| of the follow that is related to the food event. + The EVENTS.\ |EVENTS.Start| column contains the time the food bout began. -- 2.34.1