orm
Skill4 starsChanged 4 months agoMITView on GitHub
Query and persist data with the CakePHP ORM — Table and Entity objects, the query builder, associations, and parameter-safe queries against untrusted input. Use when the user needs to declare relationships (hasMany, belongsTo, belongsToMany) or eager-load related records; the user wants to compose a select, filter, order, or aggregate query with the CakePHP query builder; the user needs to read or write records using CakePHP Table objects and Entity objects. Keywords: cakephp, orm, table, entity, query-builder, associations, sql, input.
3 other projects use a version of this.
Adopted by
Most recently taken up by
- farming-labs/skillstheir own version, first seen Apr 6, 2026
- ThuPhuong1010/claude-factorytheir own version, first seen Mar 29, 2026
- ffsshhttiikk/opencode-agents-skillstheir own version, first seen Feb 28, 2026
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- ffsshhttiikk/opencode-agents-skills★ 2same name
- farming-labs/skills★ 1same name
- ThuPhuong1010/claude-factory★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository119 other files it gives its agents.
- strategy-bitrix-d7-incrementalSkill
- strategy-explicit-over-magicSkill
- strategy-framework-conventionsSkill
- strategy-legacy-safe-editsSkill
- strategy-minimal-diffSkill
- strategy-no-untested-refactorSkill
- strategy-preserve-public-apiSkill
- strategy-readonly-immutabilitySkill
- strategy-security-firstSkill
- strategy-test-drivenSkill
- openapiSkill
- paginationSkill
- rest-designSkill
- versioningSkill
- cqrsSkill
- dependency-inversionSkill
- hexagonalSkill
- repository-patternSkill
- service-layerSkill
- bitrixSkill
- findings-reportSkill
- laravelSkill
- performanceSkill
- phpSkill
- project-analysisSkill
- refactoringSkill
- roi-prioritizationSkill
- securitySkill
- stack-detectionSkill
- cache-layersSkill
- component-engineSkill
- d7-eventsSkill
- d7-loaderSkill
- d7-orm-queriesSkill
- iblock-elementsSkill
- kernel-main-moduleSkill
- localizationSkill
- controllersSkill
- validationSkill
- controllersSkill
- query-builderSkill
- routingSkill
- autoload-psr4Skill
- dependency-managementSkill
- scriptsSkill
- connection-poolingSkill
- mysql-indexingSkill
- redisSkill
- transactionsSkill
- ci-github-actionsSkill
- deployment-strategiesSkill
- docker-phpSkill
- env-configSkill
- associationsSkill
- entities-mappingSkill
- orm-basicsSkill
- entity-apiSkill
- module-developmentSkill
- routing-controllersSkill
- formsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 64
Do not use this skill for Eloquent, Doctrine, or raw PDO.
- Distinctive: line 65
Do not force the ORM query builder onto a bulk DDL or vendor-specific statement that the builder cannot express.
- Very specific: line 79
Add where(['status' => $status]) with array conditions (parameters are bound) and contain(['Authors', 'Comments']) to eager-load …
- Very specific: line 89
Put reusable query fragments in custom finder methods (findActive, findPublished) on the Table and chain them with find('active'), instead …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!-- generated: do not edit — source: knowledge/atoms/cakephp/orm/ --><!-- schema: atomVersion=3 skillVersion=2 graphVersion=1 --><!-- compile: @php-skills/compiler v1.0.0 (deterministic build) -->CakePHP ORM
When to use
- The user needs to declare relationships (hasMany, belongsTo, belongsToMany) or eager-load related records.
- The user wants to compose a select, filter, order, or aggregate query with the CakePHP query builder.
- The user needs to read or write records using CakePHP Table objects and Entity objects.
When NOT to use
- Do not use this skill for Eloquent, Doctrine, or raw PDO; the Table/Entity/query-builder API is CakePHP specific.
- Do not force the ORM query builder onto a bulk DDL or vendor-specific statement that the builder cannot express; use a parameterized raw statement via the connection instead.
Core guidance
- Eager-load associations with contain to avoid N+1 queries — When you will access related records in a loop, eager-load them with
contain()in the same query rather than lazy-accessing associations per row. - Build conditions with the array/expression API, never string interpolation — Pass conditions to
where()as an array (['status' => $value]) or via query expressions, so values are bound as parameters; never interpolate user input into a condition string.
Quick recipe
- Fetch the Table with
$this->fetchTable('Articles')(or the locator) and start a query with$table->find(). (verify:find()returns a Query object for the Articles table) - Add
where(['status' => $status])with array conditions (parameters are bound) andcontain(['Authors', 'Comments'])to eager-load associations. (verify: The generated SQL binds the status value and joins/loads the associations) - Materialize the query with
->all()(or iterate it), then read entities and their contained associations without further queries. (verify: Iterating the result issues no additional per-row queries)
Best practices
- Control which fields can be set from request data via the entity's
$_accessiblemap, and pass an explicitfields/accessibleFieldsoption tonewEntity()orpatchEntity()for sensitive columns - Put reusable query fragments in custom finder methods (
findActive,findPublished) on the Table and chain them withfind('active'), instead of repeatingwhere()clauses across controllers - For list or report queries that do not need full entities, restrict columns with
select([...])and consider->enableHydration(false)to get plain arrays
Anti-patterns
| Anti-pattern | Why it fails | Do instead |
| Marking the wildcard field accessible | A wildcard lets any request field, including privilege or ownership columns, be mass-assigned from user input. | Whitelist only the fields the form legitimately submits and keep sensitive columns false. |
| Complex query logic living in the controller | Query logic in controllers cannot be reused or unit-tested and drifts between actions that need the same rules. | Move the logic into a custom finder or Table method and call it from the controller. |
| Interpolating user input into where() strings | String interpolation bypasses parameter binding and is a direct SQL injection vulnerability. | Use array conditions or query expressions so values are bound as parameters. |
See references/anti-patterns.md.
Common mistakes
- Lazy association access triggers N+1 queries — Accessing
$row->associationinside a loop withoutcontain()runs one extra query per row. Fix: Add the association tocontain()in the original query so related rows load in a batched query. - patchEntity silently drops fields not marked accessible — Fields absent from the entity's
$_accessiblemap are silently ignored bynewEntity()/patchEntity(), so an expected column is never saved. Fix: Add the intended field to$_accessible(or pass it viaaccessibleFields) while keeping sensitive columns locked down. - A Query object is lazy and executes only on iteration — A query returned by
find()is not run until it is iterated, counted, or turned into a result withall()/toArray()/first(). Fix: Materialize the query explicitly with->all(),->toArray(),->first(), or by iterating it once you have finished building.
Version notes
- CakePHP 5 splits SelectQuery and tightens types — CakePHP 5 introduces dedicated
SelectQuery/InsertQuery/UpdateQuery/DeleteQueryclasses and requires PHP 8.1+, so type against those interfaces rather than the single CakePHP 4Queryclass.
Security
- Never interpolate untrusted input into queries — Route all user-supplied values through the builder's parameter binding — array
conditions,
IdentifierExpressionfor column names, and validated allow-lists fororder()directions — and never concatenate request data into SQL fragments.
Testing
- Activation and decision behavior are verified in
eval/scenarios/cakephp/orm.yaml.
Additional resources
- references/anti-patterns.md
- references/core.md
- references/examples.md
- references/pitfalls.md
- references/recipes.md
- references/version-differences.md
Knowledge graph
Related: cakephp/validation, php/typed-properties
<!-- graph-fragment: graph/fragments/cakephp/orm.yaml -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

