Skip to main content

a Polymorphic Association or an Exclusive Arc

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 KEY constraint 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_ID stored inside the Employees table). 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

Popular posts from this blog

Utk yg mo Bantu2 Keuangan saya
..monggo ke Bank Central Asia BCA 5520166779 a.n. Andreas Tparlaungan Manurung (Indonesia)


For those who would like to help support my finances
..please feel free to send it to Bank Central Asia (BCA) account number 5520166779 under the name Andreas Tparlaungan Manurung (Indonesia)

ANDREAS TOMMY PARLAUNGAN MANURUNG SHARED POOLING ACCOUNT MY ANDROID APKs PAGE please download here! REFRESH PAGE aka CHECK LATEST UPDATE! DOWNLOAD "SHOWING" POOL OF MY ANDROID-APK(s) aka APK CONTAINING LIST OF ALL MY ANDROID-APK(s) APP CLICK HERE FOR ALWAYS BEING UPDATED FOR MY LATEST APK! CONTOH HASIL "PROGRAM" App: Prompts' Guide aka TEMPLATE-HELPERs click here to download! Youtube and Instagram EMBEDded to Blogger/Blogspot.com SOURCE CODE Click this box to download 📥 TikTok EMBEDded to Blogger/Blogspot.com SOURCE CODE Input: BrowserLINK (mandatory) Click this box to download SHORTCUT-APPs note :  "precise" click to download R8: ronin1985.blogspot.com R2M: ronin-manu.blogspot.com Helping Download(ing) OnlineVIDEO! ...

[ERROR BUG]
ChatGPT+Gemini: TikTok → Blogger Embed Converter using Cloudflare/Online Server

🔄 Refresh Page ERROR BUG: The connection is blocked because it was initiated by a public page to connect to devices or servers on your local network. Planning: Revise Program CODE Code USING Javascript/Online Server Code NOT USING Javascript Sample Working Code aka Already Repaired! Temporary Solution is by Asking AI Assistant to do REPAIR CODE of (Not yet Repaired) Current Conversion Program Code-Output TikTok Archive – Embedded Preview TikTok Embed ▶ View this video on TikTok ⚠️ DISCLAIMER: INPUT URL LIMITATION This program is currently restricted to processing Full Browser URLs only. It does not support TikTok’s mobile "short-link" format (e.g., vt.tiktok.com ). Required Action: Users must open the video in a web browser and copy the expanded URL from the address bar before pasting it into this program. URL Conversion Example ❌ UNSUPPORTED: https://vt.tiktok.com/ZSaXoFyov/ ✅ REQ...

REPOST: Studying WATER PUMP by ROMAN ENGINEERING

*^ Ini yg Asli Gan! Mekanisme pada Concrete Pump: Kok ky Sistem Mekanik Romawi ya?! Tapi malah bisa HANYA pake PER aka bukan "MATA BOR look a like" Mekanisme Drill yg Cost Pembuatan bikin REPOT aka harus Tool SUPER Khusus Dari Material Besi yg digunakan terlihat langsung secara kasat mata Jauh Lebih Banyak drpd Per Biasa seperti yg ditunjukkan pd Video Alternatif dgn Penggunaan PER Video dr Instagram: Source: YouTube Rome's drainage machines #history #romanempire #engineering