gorm-preload

Preloads GORM associations to eliminate N+1 query problems in Go applications.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Preloading associations in GORM prevents the N+1 query problem by loading related records in bulk, reducing database round‑trips and improving performance.

Core Features & Use Cases

  • Bulk association loading: Use Preload or clause.Associations to fetch related data with minimal queries.
  • Conditional and nested preloading: Filter associated records and preload deep relationships using dot notation.
  • Combination with Joins: Switch to Joins for one‑to‑one relationships when filtering on parent records.

Quick Start

Ask the assistant to preload a user's orders and their items for a given user ID.

Frequently Asked Questions about gorm-preload

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

FAQPage Schema
How do I fix the N+1 query problem when loading related data in GORM?

To fix the N+1 query problem in GORM, use the Preload method to eagerly load associated records in bulk. This reduces database round-trips by fetching related data through minimal queries instead of executing a separate query for each parent record.

What is the best way to load nested associations in GORM using dot notation?

Loading nested associations in GORM requires using dot notation within the Preload method to fetch deep relationships. This approach allows you to specify paths to nested entities, ensuring all levels of related records are eagerly loaded.

Can I filter associated records while preloading data in GORM?

You can filter associated records during GORM preloading by passing optional conditional functions to the Preload method. This allows you to apply specific query constraints to the related data being eagerly loaded, narrowing the result set.

When should I use Joins instead of Preload for one-to-one relationships in GORM?

You should switch to Joins instead of Preload for one-to-one relationships in GORM when you need to filter parent records based on related data. Joins combines the tables in a single query, which is more efficient for this specific filtering scenario.

How does clause.Associations work for bulk loading related records in GORM?

Using clause.Associations in GORM triggers the bulk loading of all direct associations for a given model. It serves as an optional parameter in the Preload method to eagerly fetch all related records without manually specifying each relationship.