# Database Relationships

Relationship-related controller file logic differs based on type of relationship:

* [**One-to-One**](#one-to-one)
* [**One-To-Many**](#one-to-many-and-many-to-one) (and **Many-to-One**)
* [**Many-to-Many**](#many-to-many)

### Related

* [**Routes Setup**](../routes-routes.rb)

***

## Background Information & Code Examples (via ChatGPT)

### One-to-One

<figure><img src="https://2248755224-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVQm1PpPMvCvQccIZPyj%2Fuploads%2FQeq6XrWvYaerOlxtlDPu%2FCleanShot%202023-09-27%20at%2019.53.07.png?alt=media&#x26;token=ec78d23b-b55e-4775-a20f-bd5bb43c008d" alt=""><figcaption></figcaption></figure>

***

### One-to-Many (and Many-to-One)

<figure><img src="https://2248755224-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVQm1PpPMvCvQccIZPyj%2Fuploads%2FZxEavynGkkWi7qLgvW45%2FCleanShot%202023-09-27%20at%2019.53.17.png?alt=media&#x26;token=165d501a-cef3-4279-9a1a-af7e948d7c9b" alt=""><figcaption></figcaption></figure>

**Extra note on using PUT for Many-to-One**

<figure><img src="https://2248755224-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVQm1PpPMvCvQccIZPyj%2Fuploads%2FXqOhuYfWvlBE54V47i3b%2FCleanShot%202023-09-27%20at%2019.53.37.png?alt=media&#x26;token=49e428ff-2001-48c9-9d37-d26d67837bc7" alt=""><figcaption></figcaption></figure>

***

### Many-to-Many

<figure><img src="https://2248755224-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVQm1PpPMvCvQccIZPyj%2Fuploads%2FIbODpFrLWZu8ojWWez2a%2FCleanShot%202023-09-27%20at%2019.53.27.png?alt=media&#x26;token=2d6f599b-47cb-449d-b03f-1fc91a47777d" alt=""><figcaption></figcaption></figure>
