gorm-has-one
CommunityDefine one-to-one model associations
Authorliurida
Version1.0.0
Installs0
System Documentation
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.
Dependency Matrix
Required Modules
None requiredComponents
references
💻 Claude Code Installation
Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.
Please help me install this Skill: Name: gorm-has-one Download link: https://github.com/liurida/gorm-development-skill/archive/main.zip#gorm-has-one Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
Agent Skills Search Helper
Install a tiny helper to your Agent, search and equip skill from 471,000+ vetted skills library on demand.