What problem does it solve?
Provides clear patterns and operational guidance for establishing one-to-one relationships in GORM where the associated model holds the foreign key, reducing ambiguity about foreign key placement, eager loading, and lifecycle behavior between related models.
Core Features & Use Cases
- Define has one associations with conventions for default foreign key naming and how the owned model stores the owner's key.
- Configure eager loading using Preload or Joins and manage association lifecycle with Association mode operations such as Find, Append, Replace, and Clear.
- Override foreign key and reference fields, add constraint behaviors for OnUpdate/OnDelete, and model polymorphic or self-referential one-to-one relationships.
- Use Case: Model a User and a CreditCard where CreditCard stores UserID, preload the card when loading users, and enforce cascade or set-null behavior on deletion.
Quick Start
Create a User and CreditCard GORM model where CreditCard stores UserID as the foreign key and demonstrate Preload and Association operations for find and replace.