# Payment

We'll now create the <mark style="color:blue;">`Payment`</mark> model, which will be very simple.

```prisma
model Payment {
  id Int @id @default(autoincrement())

  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
```

Let's then create a relation between <mark style="color:blue;">`Order`</mark> and <mark style="color:blue;">`Payment`</mark>. An <mark style="color:blue;">`order`</mark> **may or may not** have a <mark style="color:blue;">`payment`</mark>, and a <mark style="color:blue;">`payment`</mark> **always belongs** to an <mark style="color:blue;">`order`</mark>. Therefore, we have a **one-to-one** relation. Lastly, we want that an <mark style="color:blue;">`order`</mark> is deleted together with its <mark style="color:blue;">`payment`</mark>.

So, in the <mark style="color:blue;">`Order`</mark> model we should have

```prisma
payment Payment?
```

And in <mark style="color:blue;">`Payment`</mark>

```prisma
order   Order @relation(fields: [orderId], references: [id], onDelete: Cascade)
orderId Int   @unique
```

Then, let's generate and run its migration

```sh
yarn migrate:create create-payment
yarn migrate:run
```

And now, create the payments resource. Remember to choose <mark style="color:red;">**no**</mark> to **CRUD entry points**.

```sh
nest g res domain/payments
```

<mark style="color:green;">**Commit**</mark> - Creating payment model
