gorm-has-many

Define one-to-many GORM relationships with foreign keys and association operations.

Updated Apr 4, 2026
One-click install
npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-has-many
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: gorm-has-many
Source: https://github.com/liurida/gorm-development-skill/tree/main/has_many
Command: npx skills add https://github.com/liurida/gorm-development-skill --skill gorm-has-many

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Developers often struggle to correctly define and manage one-to-many relationships in GORM, handling foreign keys, eager loading, and association lifecycle operations.

Core Features & Use Cases

  • Define has‑many relationships with automatic foreign key inference.
  • Customize foreign keys and reference fields via GORM tags.
  • Apply constraints such as cascade updates or delete actions.
  • Perform association operations: append, replace, delete, clear, count, and preload.
  • Support self‑referential hierarchies and polymorphic associations.
  • Example use case: a User model with many CreditCard records, requiring eager loading for display dashboards.

Quick Start

Ask the skill to create a User with associated CreditCards and preload them for a report.

Frequently Asked Questions about gorm-has-many

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I define a one-to-many relationship in GORM with a custom foreign key?

To define a one-to-many relationship in GORM with a custom foreign key, use GORM tags to specify the foreign key and reference fields on your model structs, overriding automatic foreign key inference for accurate association mapping.

How does eager loading work for GORM has-many associations?

Eager loading for GORM has-many associations works by using the Preload feature to fetch parent and child records in a single query, preventing N+1 query problems when displaying related data like a user and their credit cards.

Can I apply cascade delete constraints to a GORM has-many relationship?

Yes, you can apply cascade delete constraints to a GORM has-many relationship by configuring the constraint settings within your model tags, ensuring associated child records are automatically deleted with the parent.

What is the best way to manage GORM association operations like append and replace?

The best way to manage GORM association operations like append and replace is to use the built-in association mode, allowing you to append, replace, delete, clear, and count related records efficiently without manual foreign key updates.

Does GORM support self-referential has-many hierarchies and polymorphic associations?

Yes, GORM supports self-referential has-many hierarchies and polymorphic associations, allowing a model to reference itself for parent-child trees and enabling multiple models to share a single association table through polymorphic configuration.

Why are my GORM has-many associated records not loading correctly?

GORM has-many associated records may not load correctly if the foreign key inference fails, requiring you to explicitly define the foreign key and reference fields via GORM tags or ensure you are using Preload for eager loading.