Hi,
According to the document:
There are 4 types of relationships: one-to-one, one-to-many, many-to-one and many-to-many
<
: one-to-many. E.g: users.id < posts.user_id
>
: many-to-one. E.g: posts.user_id > users.id
-
: one-to-one. E.g: users.id - user_infos.user_id
<>
: many-to-many. E.g: authors.id <> books.id
I need the last one, not the first one (which is the syntax you suggest).
For example:
Table schema.image {
id integer [pk]
url varchar
}
Table schema.content_item {
id integer [pk]
heading varchar
description varchar
}
Ref: schema.image.id <> schema.content_item.id
Table schema.footer_item {
id integer [pk]
left varchar
centre varchar
right varchar
}
Ref: schema.image.id <> schema.footer_item.id
…results in:
CREATE SCHEMA "schema";
CREATE TABLE "schema"."image" (
"id" integer PRIMARY KEY,
"url" varchar
);
CREATE TABLE "schema"."content_item" (
"id" integer PRIMARY KEY,
"heading" varchar,
"description" varchar
);
CREATE TABLE "schema"."footer_item" (
"id" integer PRIMARY KEY,
"left" varchar,
"centre" varchar,
"right" varchar
);
CREATE TABLE "image_content_item" (
"image_id" integer NOT NULL,
"content_item_id" integer NOT NULL,
PRIMARY KEY ("image_id", "content_item_id")
);
ALTER TABLE "image_content_item" ADD FOREIGN KEY ("image_id") REFERENCES "schema"."image" ("id");
ALTER TABLE "image_content_item" ADD FOREIGN KEY ("content_item_id") REFERENCES "schema"."content_item" ("id");
CREATE TABLE "image_footer_item" (
"image_id" integer NOT NULL,
"footer_item_id" integer NOT NULL,
PRIMARY KEY ("image_id", "footer_item_id")
);
ALTER TABLE "image_footer_item" ADD FOREIGN KEY ("image_id") REFERENCES "schema"."image" ("id");
ALTER TABLE "image_footer_item" ADD FOREIGN KEY ("footer_item_id") REFERENCES "schema"."footer_item" ("id");
What I want it to do:
CREATE SCHEMA "schema";
CREATE TABLE "schema"."image" (
"id" integer PRIMARY KEY,
"url" varchar
);
CREATE TABLE "schema"."content_item" (
"id" integer PRIMARY KEY,
"heading" varchar,
"description" varchar
);
CREATE TABLE "schema"."footer_item" (
"id" integer PRIMARY KEY,
"left" varchar,
"centre" varchar,
"right" varchar
);
CREATE TABLE "schema"."image_content_item" (
"image_id" integer NOT NULL,
"content_item_id" integer NOT NULL,
PRIMARY KEY ("image_id", "content_item_id")
);
ALTER TABLE "schema"."image_content_item" ADD FOREIGN KEY ("image_id") REFERENCES "schema"."image" ("id");
ALTER TABLE "schema"."image_content_item" ADD FOREIGN KEY ("content_item_id") REFERENCES "schema"."content_item" ("id");
CREATE TABLE "schema"."image_footer_item" (
"image_id" integer NOT NULL,
"footer_item_id" integer NOT NULL,
PRIMARY KEY ("image_id", "footer_item_id")
);
ALTER TABLE "schema"."image_footer_item" ADD FOREIGN KEY ("image_id") REFERENCES "schema"."image" ("id");
ALTER TABLE "schema"."image_footer_item" ADD FOREIGN KEY ("footer_item_id") REFERENCES "schema"."footer_item" ("id");
(note “schema” in front of “image_content_item” & “image_footer_item” tables…