new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

database-relations/polymorphic

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Polymorphic relations definition

Polymorphic relationships allow a single relationship to point to different types of entities or tables. They create more flexible relationships when different kinds of data share some commonality. Instead of creating separate tables and relationships for each type, a polymorphic approach uses a single relationship to reference multiple possible table types.

Polymorphic relations use cases

Polymorphic relationships are used in scenarios like: Comments that can be attached to articles, products, or videos (using commentable_type and commentable_id columns), and Notifications that can relate to users, orders, or system events (using notifiable_type and notifiable_id columns).

Polymorphic relationships allow a single relationship to point to different entity types

Polymorphic relationships are advanced relationships that allow a single relationship to point to different types of entities or tables. This creates more flexible and adaptable relationships when different kinds of data share some commonality. For example, an activities log might have a single Comment table where comments can be related to articles, products, or videos. Instead of creating separate relationship columns for each type (article_id, product_id, video_id), a polymorphic approach uses a commentable_type column (indicating the type) and a commentable_id column (the ID of that type).

Polymorphic relationships are handled at the application level

Polymorphic relationships are more complex and are typically handled at the application level or using advanced database features specific to the database system. Standard SQL does not have direct, built-in support for enforcing polymorphic foreign key constraints in the same way as regular foreign keys.

Give your agent this brain