HowToCheck - EtheaDev/kitto2 GitHub Wiki
How to validate data before storing
If you want to operate a validation check before storing data in the database, you have to:
- declare and write a rule for the model in Delphi
rule.pasunit - define the node
Rules:for the model
example form HelloKitto:
# rule.pas
type
TCheckDuplicateInvitations = class(TKRuleImpl)
public
procedure BeforeAdd(const ARecord: TKRecord); override;
end;
procedure TCheckDuplicateInvitations.BeforeAdd(const ARecord: TKRecord);
begin
if ARecord.Store.Count('INVITEE_ID', ARecord.FieldByName('INVITEE_ID').Value) > 1 then
RaiseError(_('Cannot invite the same girl twice.'));
end;
# model Invitation.yaml
ModelName: Invitation
Fields:
.....
Rules:
CheckDuplicateInvitations: