Payment
The Payment
resource will be pretty simple. This time, choose no to CRUD entry points.
nest g res domain/payments
This time, as we didn't create CRUD entry points, an entity was not created, so please create it in entities -> payment.entity. Then, define the attributes.
id: number;
registryDates: RegistryDates;
Also associate the ORM decorators, and register it inside the TypeOrmModule
.
An order may or may not have a payment, and a payment always belongs to an order. So we can declare a one-to-one relationship, starting on the order's side.
@OneToOne(() => Payment, (payment) => payment.order, { cascade: true })
payment: Payment;
We can now do the same on the payment's side.
@OneToOne(() => Order, (order) => order.payment, {
nullable: false,
onDelete: 'CASCADE',
})
@JoinColumn()
order: Order;
Let's finish by generating and running the migration create-payment.
Commit - Creating payment entity and handling one to one relation
Last updated