koan-relationships

Official

Manage entity links, no ORM hassle.

Authorsylin-org
Version1.0.0
Installs0

System Documentation

What problem does it solve?

Managing relationships between entities in traditional ORMs often involves complex mapping configurations and can lead to inefficient N+1 query problems. This Skill simplifies relationship handling in Koan Framework using foreign keys and efficient batch loading.

Core Features & Use Cases

  • Foreign Key-Based Relationships: Define one-to-many, many-to-one, and optional relationships using simple foreign key properties.
  • Navigation Helpers: Add convenient methods directly on entities (e.g., user.GetTodos(), todo.GetUser()) to traverse relationships.
  • Prevent N+1 Queries: Implement efficient batch loading patterns to fetch related entities in a single query, dramatically improving performance for collections.
  • Hierarchical Data: Easily model parent-child relationships and retrieve nested data structures.
  • Use Case: Define a User with many Todo items. Instead of fetching each user's todos individually (N+1), batch load all user IDs, then fetch all associated todos in one optimized query.

Quick Start

To define a one-to-many relationship between User and Todo: public class User : Entity<User> { public string Name { get; set; } = ""; public Task<List<Todo>> GetTodos() => Todo.Query(t => t.UserId == Id); } public class Todo : Entity<Todo> { public string UserId { get; set; } = ""; public Task<User?> GetUser() => User.Get(UserId); } To prevent N+1 queries when loading multiple todos and their users: var userIds = todos.Select(t => t.UserId).Distinct().ToArray(); var users = await User.Get(userIds); // Single query

Dependency Matrix

Required Modules

None required

Components

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: koan-relationships
Download link: https://github.com/sylin-org/koan-framework/archive/main.zip#koan-relationships

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 223,000+ vetted skills library on demand.