- Get link
- X
- Other Apps
While often discussed in the same breath, Polymorphic Associations and Exclusive Arcs represent two distinct architectural strategies for handling multi-source relationships—differing primarily in how they balance application flexibility against database-level integrity.
1. Polymorphic Association (The ORM Approach)
A polymorphic association typically relies on a two-column pattern: an entity type string (e.g., owner_type) and an ID (e.g., owner_id). This pattern is heavily favored by modern Object-Relational Mappers (ORMs) like Ruby on Rails, Laravel, and Hibernate.
- How it works: A single transaction record stores a string indicating the parent table name alongside the primary key value of that parent.
- Advantages: High flexibility. You can introduce new parent entity types without altering the core transaction table schema.
- Disadvantages: Loss of Native Referential Integrity. Relational databases cannot enforce a
FOREIGN KEYconstraint on a column whose target table changes dynamically.
2. Exclusive Arc (The Relational Constraint Approach)
An exclusive arc uses individual, nullable foreign key columns for each potential parent table (vendor_id, employee_id, agency_id), guarded by a strict database CHECK constraint.
- How it works: Every potential parent relationship has its own dedicated physical column, but database constraints ensure that only one column holds a value while the rest remain
NULL. - Advantages: Strict Referential Integrity. Every foreign key is bound natively to its respective parent table via standard RDBMS constraints.
- Disadvantages: Schema rigidity. Adding a new parent entity requires a database migration to add a new column and update the check constraint.
Architectural Insight: For financial reporting and public sector accounting workflows where audit trails and strict constraints are non-negotiable, the Exclusive Arc pattern is typically the safer database-level choice.
3. Summary Comparison
| Feature | Polymorphic Association | Exclusive Arc |
|---|---|---|
| Column Structure | type + id (2 columns) |
Multiple FK columns |
| Referential Integrity | Handled by Application / ORM | Enforced natively by Database Engine |
| Extensibility | High (No schema changes needed) | Low (Requires DDL migration) |
| Audit Compliance | Weaker (Risk of unconstrained pointers) | Stronger (Fully compliant trails) |
The Many-to-One (N:1) Concept
A Many-to-One (N:1) relationship occurs when multiple records in a child table can be associated with a single parent record in a related table. However, each record in the child table points back to only one specific parent.
For example, consider a corporate or academic structure:
- Multiple employees can work within a single department.
- Multiple transaction lines can belong to a single general ledger account.
How It Works: Implementation & Foreign Keys
Unlike Many-to-Many relationships that require a third junction table, a Many-to-One relationship is implemented directly within the existing tables using a standard Foreign Key:
- The "One" Side (Parent Table): Holds the primary key (e.g.,
Department_ID). Each department exists uniquely as a single record. - The "Many" Side (Child Table): Houses the foreign key column pointing to the parent (e.g.,
Department_IDstored inside theEmployeestable). Multiple employee rows can carry the exact same department ID.
Relationship Symmetry: Many-to-One vs. One-to-Many
From a structural standpoint, Many-to-One and One-to-Many are identical designs; the distinction depends entirely on which direction you query the data:
- Viewed from the department table looking down at the employees, it is a One-to-Many (1:N) relationship.
- Viewed from the employee table looking up at the department, it is a Many-to-One (N:1) relationship.
When designing complex accounting databases or public sector financial systems, a single transaction ledger often needs to collect foreign keys dynamically from multiple distinct parent tables. This structural pattern is known as an Exclusive Arc or Polymorphic Association.
1. Architecture: The Exclusive Arc Pattern
Instead of duplicating transaction tables for every unique entity type, a central child table houses nullable foreign keys pointing to each respective master table, enforced by a strict validation rule.
Audit Note: Standard relational engines require custom check constraints to ensure that an entry references one and only one parent entity type at any given moment.
2. Schema Definition Table
| Table Name | Role | Key Components |
|---|---|---|
Vendors |
Parent Source | Vendor_ID (PK) |
Employees |
Parent Source | Employee_ID (PK) |
Disbursement_Lines |
Central Collector | Line_ID, Nullable FKs |
3. SQL DDL Implementation
The code block below demonstrates how to enforce the exclusive relationship constraint natively via SQL:
CREATE TABLE Disbursement_Lines (
Line_ID INT PRIMARY KEY,
Amount DECIMAL(15,2) NOT NULL,
Vendor_ID VARCHAR(20) NULL,
Employee_ID VARCHAR(20) NULL,
Agency_ID VARCHAR(20) NULL,
CONSTRAINT fk_disb_vendor FOREIGN KEY (Vendor_ID) REFERENCES Vendors(Vendor_ID),
CONSTRAINT fk_disb_employee FOREIGN KEY (Employee_ID) REFERENCES Employees(Employee_ID),
CONSTRAINT fk_disb_agency FOREIGN KEY (Agency_ID) REFERENCES Agencies(Agency_ID),
-- Exclusive Arc Constraint: Exactly one reference must be active
CONSTRAINT chk_single_payee CHECK (
(Vendor_ID IS NOT NULL AND Employee_ID IS NULL AND Agency_ID IS NULL) OR
(Vendor_ID IS NULL AND Employee_ID IS NOT NULL AND Agency_ID IS NULL) OR
(Vendor_ID IS NULL AND Employee_ID IS NULL AND Agency_ID IS NOT NULL)
)
);
Comments