From bee862c2fa6ef354c37358142a6ede389101e26b Mon Sep 17 00:00:00 2001 From: steve-chavez Date: Mon, 21 Oct 2024 14:45:53 -0500 Subject: [PATCH] docs: inline one-to-one relationship SQL More direct than having to jump to the sample film database definition. --- docs/references/api/resource_embedding.rst | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/docs/references/api/resource_embedding.rst b/docs/references/api/resource_embedding.rst index 6a5ae38b3..3aafa76a6 100644 --- a/docs/references/api/resource_embedding.rst +++ b/docs/references/api/resource_embedding.rst @@ -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 ` as an example). -- When the foreign key is a primary key as specified in the :ref:`sample film database `. -- 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