API with NestJS #170. Polymorphic associations with PostgreSQL and Drizzle ORM
Briefly

Polymorphic associations allow for a single table to represent related data from multiple sources, optimizing code and preventing redundancy by uniting similar functionalities under a single entity.
Implementing polymorphic associations using a single column pointing to different tables could lead to integrity issues; thus, having separate foreign keys is a preferred approach.
To preserve database integrity, it’s essential to ensure that a comment relates to either a photo or an article, enforcing checks that prevent this ambiguity.
The design using Drizzle ORM generates two separate foreign key constraints, ensuring that while a comment may not relate to both, its linkage is validated by the constraints.
Read at Marcin Wanago Blog - JavaScript, both frontend and backend
[
|
]