summaryrefslogtreecommitdiff
path: root/lib/query/tests/create.t
diff options
context:
space:
mode:
Diffstat (limited to 'lib/query/tests/create.t')
-rw-r--r--lib/query/tests/create.t74
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/query/tests/create.t b/lib/query/tests/create.t
index 38a4630..46e3940 100644
--- a/lib/query/tests/create.t
+++ b/lib/query/tests/create.t
@@ -149,3 +149,77 @@ table but a dedicated table is created:
, FOREIGN KEY("parent") REFERENCES "entity"("id")
, FOREIGN KEY("target") REFERENCES "user_type_list"("id") )
+A declared list gets its own table, holding an id. A reference field pointing
+to a list is an integer column constrained by a foreign key to the list table:
+
+ $ tests --schema "user_type_list" "entity" <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "user_type_list",
+ > "source": "csv"
+ > }
+ > ],
+ > "content": [
+ > {
+ > "id": "entity",
+ > "section": [
+ > {
+ > "field": [
+ > {
+ > "name": "user_type",
+ > "label": {},
+ > "type": { "content": "user_type_list" }
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > EOF
+ CREATE TABLE "user_type_list"
+ ( "id" INTEGER PRIMARY KEY )
+ CREATE TABLE "entity"
+ ( "id" INTEGER PRIMARY KEY
+ , "user_type" INTEGER
+ , FOREIGN KEY("user_type") REFERENCES "user_type_list"("id") )
+
+A multivaluated reference to a list gets the usual dedicated table, with the
+target column referencing the list table:
+
+ $ tests --schema "entity.user_type" <<EOF
+ > {
+ > "list": [
+ > {
+ > "id": "user_type_list",
+ > "source": "csv"
+ > }
+ > ],
+ > "content": [
+ > {
+ > "id": "entity",
+ > "section": [
+ > {
+ > "field": [
+ > {
+ > "name": "user_type",
+ > "label": {},
+ > "type": {
+ > "content": "user_type_list",
+ > "multivaluated": true
+ > }
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > ]
+ > }
+ > EOF
+ CREATE TABLE "entity.user_type"
+ ( "id" INTEGER PRIMARY KEY
+ , "parent" INTEGER NOT NULL
+ , "target" INTEGER NOT NULL
+ , FOREIGN KEY("parent") REFERENCES "entity"("id")
+ , FOREIGN KEY("target") REFERENCES "user_type_list"("id") )