Skip to content

Commit

Permalink
relations.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jemgillam committed Feb 18, 2025
1 parent f2ec904 commit 9faf265
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions postgraphile/website/postgraphile/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ An example of a foreign key constraint when defining a table would be the
`REFERENCES` keyword below:

```sql
CREATE TABLE app_public.users (
create table app_public.users (
-- ...
organization_id int NOT NULL
organization_id int not null
/* highlight-next-line */
REFERENCES app_public.organizations ON DELETE CASCADE,
references app_public.organizations on delete cascade,
-- ...
);
CREATE INDEX ON app_public.users (organization_id);
create index on app_public.users (organization_id);
```

Alternatively a foreign key constraint can be added after table creation:

```sql
ALTER TABLE users
ADD CONSTRAINT users_organization_id_fkey
FOREIGN KEY (organization_id)
REFERENCES organizations
ON DELETE CASCADE;
CREATE INDEX ON users (organization_id);
alter table users
add constraint users_organization_id_fkey
foreign key (organization_id)
references organizations
on delete cascade;
create index on users (organization_id);
```

You can read more about defining foreign key constraints, including constraints
that utilise multiple columns, in the
that utilize multiple columns, in the
[PostgreSQL documentation](https://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK).

PostGraphile detects and exposes one-to-one, one-to-many and many-to-one
Expand Down
22 changes: 11 additions & 11 deletions postgraphile/website/versioned_docs/version-4/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ An example of a foreign key constraint when defining a table would be the
`REFERENCES` keyword below:

```sql {4}
CREATE TABLE app_public.users (
create table app_public.users (
-- ...
organization_id int NOT NULL
REFERENCES app_public.organizations ON DELETE CASCADE,
organization_id int not null
references app_public.organizations on delete cascade,
-- ...
);
CREATE INDEX ON app_public.users (organization_id);
create index on app_public.users (organization_id);
```

Alternatively a foreign key constraint can be added after table creation:

```sql
ALTER TABLE users
ADD CONSTRAINT users_organization_id_fkey
FOREIGN KEY (organization_id)
REFERENCES organizations
ON DELETE CASCADE;
CREATE INDEX ON users (organization_id);
alter table users
add constraint users_organization_id_fkey
foreign key (organization_id)
references organizations
on delete cascade;
create index on users (organization_id);
```

You can read more about defining foreign key constraints, including constraints
that utilise multiple columns, in the
that utilize multiple columns, in the
[PostgreSQL documentation](https://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK).

PostGraphile detects and exposes one-to-one, one-to-many and many-to-one
Expand Down
22 changes: 11 additions & 11 deletions postgraphile/website/versioned_docs/version-5/relations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ An example of a foreign key constraint when defining a table would be the
`REFERENCES` keyword below:

```sql
CREATE TABLE app_public.users (
create table app_public.users (
-- ...
organization_id int NOT NULL
organization_id int not null
/* highlight-next-line */
REFERENCES app_public.organizations ON DELETE CASCADE,
references app_public.organizations on delete cascade,
-- ...
);
CREATE INDEX ON app_public.users (organization_id);
create index on app_public.users (organization_id);
```

Alternatively a foreign key constraint can be added after table creation:

```sql
ALTER TABLE users
ADD CONSTRAINT users_organization_id_fkey
FOREIGN KEY (organization_id)
REFERENCES organizations
ON DELETE CASCADE;
CREATE INDEX ON users (organization_id);
alter table users
add constraint users_organization_id_fkey
foreign key (organization_id)
references organizations
on delete cascade;
create index on users (organization_id);
```

You can read more about defining foreign key constraints, including constraints
that utilise multiple columns, in the
that utilize multiple columns, in the
[PostgreSQL documentation](https://www.postgresql.org/docs/current/static/ddl-constraints.html#DDL-CONSTRAINTS-FK).

PostGraphile detects and exposes one-to-one, one-to-many and many-to-one
Expand Down

0 comments on commit 9faf265

Please sign in to comment.