orm-patterns

Optimize PHP ORM data access patterns and detect N+1 queries.

2|Updated Feb 28, 2024
One-click install
npx skills add https://github.com/coagus/php-api-builder --skill orm-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: orm-patterns
Source: https://github.com/coagus/php-api-builder/tree/main/.claude/skills/orm-patterns
Command: npx skills add https://github.com/coagus/php-api-builder --skill orm-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The ORM patterns skill clarifies when to apply Active Record vs Data Mapper, how to avoid N+1 queries, and how to design robust, scalable data access in PHP projects, reducing coupling and improving testability.

Core Features & Use Cases

  • Active Record vs Data Mapper decisions and anti-patterns
  • Identity map, unit of work, eager vs lazy loading
  • Scopes, query builder composition, and relationship cascading
  • Soft deletes, optimistic locking, and performance profiling
  • Guidelines for reviewing and optimizing ORM-layer code in the php-api-builder library to achieve maintainable, performant data access

Quick Start

Review the ORM patterns discussion to evaluate and refactor your models for scalable data access.

Frequently Asked Questions about orm-patterns

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

FAQPage Schema
How do I fix N+1 query problems in PHP ORM projects?

To fix N+1 query problems in PHP ORM projects, apply eager loading instead of lazy loading for related records. This skill helps spot N+1 issues during code review and guides selecting the correct loading strategy to optimize data access performance.

When should I use Active Record vs Data Mapper in PHP?

Use Active Record for simpler domain logic and Data Mapper for complex business rules requiring loose coupling and high testability. This skill provides evaluation guidelines to distinguish these ORM patterns, their anti-patterns, and when to apply each for scalable data access.

How do I define safe cascade rules for ORM relationships?

Defining safe cascade rules for ORM relationships requires evaluating your entity dependencies and lifecycle operations. This skill provides guidelines for relationship cascading, query builder composition, and scopes to ensure robust data access without orphaned records or unintended deletions.

Can I use optimistic locking and soft deletes with PHP ORM patterns?

Yes, you can implement optimistic locking and soft deletes within PHP ORM patterns. This skill covers these specific features alongside identity maps and unit of work patterns to help you design robust data access layers that prevent concurrent update conflicts and preserve data history.

What are common ORM anti-patterns that hurt PHP application performance?

Common ORM anti-patterns hurting PHP performance include unoptimized lazy loading causing N+1 queries, improper relationship cascading, and misconfigured identity maps. This skill helps identify these issues through performance profiling guidelines to achieve maintainable, performant data access.

Does this ORM patterns skill work with the php-api-builder library?

Yes, this skill provides specific guidelines for reviewing and optimizing ORM-layer code within the php-api-builder library. It supports evaluating Active Record and Data Mapper implementations to achieve scalable, performant data access tailored to that environment.