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 · MySQL · all subjects

relations/polymorphic

5 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 relationships concept

Polymorphic relationships allow a single relationship to point to different types of entities or tables, creating flexible relationships when different kinds of data share commonality. For example, an activities log might have comments that could relate to articles, products, or videos. Rather than separate foreign key columns for each type, a polymorphic approach uses a type identifier column and an id column pointing to different tables. Standard SQL does not have direct, built-in support for enforcing polymorphic foreign key constraints; they are typically handled at the application level or using advanced database features.

Polymorphic relationships use cases

Common use cases for polymorphic relationships include comments or reviews that relate to different content types (articles, products, videos), and notifications that can relate to different entities (users, orders, system events). Instead of creating separate tables and relationships for each type, polymorphic relationships use a flexible type identifier and entity id to point to any related table.

Predefined where filters in relations for polymorphic data

Relations can include a where clause to filter related data based on conditions. The where clause applies only to the target table (the table being related TO, not FROM). For example, verifiedUsers: r.many.users({ from: ..., to: ..., where: { verified: true } }) fetches only verified users in the relation. This implements a form of polymorphic relations.

Polymorphic relationships definition

Polymorphic relationships allow a single relationship to point to different types of entities or tables. They provide flexibility when different kinds of data share commonality. For example, a Comments table might reference Articles, Products, or Videos through polymorphic_type and polymorphic_id columns.

Polymorphic relationships implementation complexity

Polymorphic relationships are more complex and are typically handled at the application level rather than enforced at the database level. 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