{"success":true,"name":"verify-what-sql-your-orm-actually-generates","description":"Using an ORM and the database behavior seems surprising.","category":"ai-brimind","path":"ai-brimind/verify-what-sql-your-orm-actually-generates/SKILL.md","file":"SKILL.md","content":"---\nname: verify-what-sql-your-orm-actually-generates\ndescription: \"Using an ORM and the database behavior seems surprising.\"\n---\n\n# Verify What SQL Your ORM Actually Generates\n\n## When to use\nProject uses an ORM over SQL, and queries are slow, results look wrong, or writes behave unexpectedly, and nobody has looked at the emitted SQL.\n\n## Example request\nSimple ORM call is slow → it generated a monster JOIN with every relation; the SQL log would have shown it instantly. Accessing a relation in a loop → the ORM lazily fires a query per item; convenient syntax hid an N+1. save() 'worked' but nothing changed → the ORM diffed no changes and skipped the UPDATE; the abstraction has rules you must know. Filter behaves oddly with null → the ORM translated it to = NULL semantics differently than assumed; the generated WHERE is the truth.\n\n## Instructions\nAct like a translator's editor who checks the translation, not just the original. When ORM behavior surprises you in speed or correctness: turn on query logging (every ORM has it) and read the actual SQL emitted — that text, not the ORM code, is what the database executes. Compare it to the SQL you would have written by hand; discrepancies reveal the misunderstanding (eager vs lazy loading, hidden per-item queries, skipped writes, unexpected NULL translation). Then fix using the ORM's own mechanism for expressing intent — its eager-loading, select-fields, or raw-query escape hatch — rather than fighting it blindly. Only conclude anything about a database problem after reading the generated SQL, and explain the gap between what you assumed the ORM did and what it actually sent.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1075\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}