Skip to content

Validation query for cardinality is not being generated when another necessity is present #326

@Ereski

Description

@Ereski

In this example:

Term: bar

Term: foo
    Concept Type: Integer (Type)

Fact Type: bar taints foo
    Necessity: each bar taints at least one foo
    Necessity: each bar taints a foo that is greater than 10.

sbvr-compiler does not generate a validation query for the first necessity, although the schema takes that into account:

                --
                -- Create table statements
                --

CREATE TABLE IF NOT EXISTS "bar" (
        "created at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
,       "id" SERIAL NOT NULL PRIMARY KEY
);

CREATE TABLE IF NOT EXISTS "bar-taints-foo" (
        "created at" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
,       "bar" INTEGER NOT NULL
,       "taints-foo" INTEGER NOT NULL
,       "id" SERIAL NOT NULL PRIMARY KEY
,       FOREIGN KEY ("bar") REFERENCES "bar" ("id")
,       UNIQUE("bar", "taints-foo")
);



                --
                -- Rule validation queries
                --


-- It is necessary that each bar taints at least one foo
SELECT NOT EXISTS (
        SELECT 1
        FROM "bar" AS "bar.0"
        WHERE NOT EXISTS (
                SELECT "bar.0-taints-foo.1"."foo"
                FROM "bar-taints-foo" AS "bar.0-taints-foo.1"
                WHERE "bar.0-taints-foo.1"."bar" = "bar.0"."id"
        )
) AS "result";

If the second necessity is removed, the validation query for the first necessity is outputted as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions