Module: SpreeCmCommissioner::Integrations::IntegrationMappable

Extended by:
ActiveSupport::Concern
Included in:
Guest
Defined in:
app/models/concerns/spree_cm_commissioner/integrations/integration_mappable.rb

Overview

IntegrationMappable provides a polymorphic mapping layer between internal records and external integration IDs.

Design Rationale: Why use a separate mapping table instead of adding external_id columns directly?

  1. **No Schema Changes Required**: Adding a new integration doesn’t require migrations to add columns to every table. The mapping table is reusable across all models that include this concern.

  2. **Polymorphic Scalability**: A single mapping table handles multiple record types (Spree::Product, Spree::Taxon, SeatLayout, etc.) without duplicating external_id columns across the schema.

  3. **Multiple Source Support**: Records can have mappings to multiple integrations simultaneously. A single product might be synced from StadiumXV1, LarrytaV1, and other sources. Direct columns would require one per integration.

  4. **Acceptable Performance Trade-off**: While joins are slightly slower than direct column lookups, the performance impact is negligible in practice because:

    • Lookups occur primarily during background jobs (async, not blocking user requests)

    • Integration sync operations (incremental, full, webhook)

    • Occasional user-triggered operations (not on every page load)

    The flexibility and maintainability gains far outweigh the minimal performance cost.