Reference implementation for the Phoenix Architecture. Work in progress. aicoding.leaflet.pub/
ai coding crazy

fix: null vs undefined in FK validation — systemic prompt rule

When project_id is null (no project selected), the check
"if (project_id !== undefined)" passes and tries to look up
project with id=null, returning "Project not found".

Systemic: LLM doesn't distinguish null (explicitly none) from
undefined (not provided) in FK validation. Architecture prompt
now requires "if (fk != null)" (loose equality) to skip validation
for both null and undefined.

+2 -1
examples/todo-app/data/app.db-shm

This is a binary file and will not be displayed.

examples/todo-app/data/app.db-wal

This is a binary file and will not be displayed.

+1 -1
examples/todo-app/src/generated/todos/tasks.ts
··· 165 165 const { title, description, priority, due_date, project_id } = result.data; 166 166 167 167 // Validate project exists if provided 168 - if (project_id !== undefined) { 168 + if (project_id != null) { 169 169 const project = db.prepare('SELECT id FROM projects WHERE id = ?').get(project_id); 170 170 if (!project) { 171 171 return c.json({ error: 'Project not found' }, 400);
+1
src/architectures/sqlite-web-api.ts
··· 144 144 - Include \`created_at TEXT NOT NULL DEFAULT (datetime('now'))\` for timestamps. 145 145 - Foreign key columns must match the referenced table: \`category_id INTEGER REFERENCES categories(id)\` 146 146 - Nullable foreign key fields in Zod schemas MUST use \`.nullable().optional()\` — both null and undefined mean "no reference". Example: \`project_id: z.number().int().nullable().optional()\` 147 + - When validating FK references before INSERT, check \`if (project_id != null)\` (loose equality) to skip validation for BOTH null and undefined. Never use \`!== undefined\` alone. 147 148 148 149 ### Stats / aggregate endpoints 149 150 - If the spec describes a stats or aggregate endpoint, implement it as a route on the same router.