Skip to content

Commit

Permalink
docs: inline one-to-one relationship SQL
Browse files Browse the repository at this point in the history
More direct than having to jump to the sample film database definition.
  • Loading branch information
steve-chavez committed Oct 21, 2024
1 parent 5ca969f commit bee862c
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions docs/references/api/resource_embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,25 @@ The join table is also detected if the composite key has additional columns.
One-to-one relationships
------------------------

One-to-one relationships are detected in two ways.
One-to-one relationships are detected in two ways. (We'll use the ``films`` and ``technical_specs`` tables from the :ref:`sample film database <erd_film>` as an example).

- When the foreign key is a primary key as specified in the :ref:`sample film database <erd_film>`.
- When the foreign key has a unique constraint.
- When the foreign key is also a primary key.

.. code-block:: postgres
create table technical_specs(
film_id int references films(id) unique,
runtime time,
camera text,
sound text
film_id int references films(id) primary key
-- ...
);
- Or when the foreign key has a unique constraint.

.. code-block:: postgres
create table technical_specs(
id int primary key
, film_id int references films(id) unique
-- ...
);
.. code-block:: bash
Expand Down

0 comments on commit bee862c

Please sign in to comment.