{"record":{"id":"f3b9ce597c70144a","repo":"n8n-io/n8n","slug":"key-column-was-not-found-in-the-metadata-name","errorCode":null,"errorMessage":"${key} column was not found in the ${metadata.name} entity.","messagePattern":"(.+?) column was not found in the (.+?) entity\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/typeorm/src/find-options/FindOptionsUtils.ts","lineNumber":215,"sourceCode":"        } else if (options.loadRelationIds instanceof Object) {\n            qb.loadAllRelationIds(options.loadRelationIds as any);\n        }\n\n        if (options.where)\n            qb.where(options.where);\n\n        if ((options as FindManyOptions<T>).skip)\n            qb.skip((options as FindManyOptions<T>).skip!);\n\n        if ((options as FindManyOptions<T>).take)\n            qb.take((options as FindManyOptions<T>).take!);\n\n        if (options.order)\n            Object.keys(options.order).forEach(key => {\n                const order = ((options as FindOneOptions<T>).order as any)[key as any];\n\n                if (!metadata.findColumnWithPropertyPath(key))\n                    throw new Error(`${key} column was not found in the ${metadata.name} entity.`);\n\n                switch (order) {\n                    case 1:\n                        qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n                        break;\n                    case -1:\n                        qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n                        break;\n                    case \"ASC\":\n                        qb.addOrderBy(qb.alias + \".\" + key, \"ASC\");\n                        break;\n                    case \"DESC\":\n                        qb.addOrderBy(qb.alias + \".\" + key, \"DESC\");\n                        break;\n                }\n            });\n\n        return qb;","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/typeorm/src/find-options/FindOptionsUtils.ts#L197-L233","documentation":"FindOptionsUtils (FindManyOptions branch) iterates options.order keys and resolves each via metadata.findColumnWithPropertyPath. Any key without a matching column throws `${key} column was not found in the ${metadata.name} entity.` Ordering is by column property name, not DB column name, and relations are not valid order keys here.","triggerScenarios":"Passing `order: { created_at: 'DESC' }` (DB column) instead of `{ createdAt: 'DESC' }` (property); ordering by a relation field without selecting/joining it; ordering by a getter or virtual property; ordering by a column removed in a refactor; ordering by a snake_case column when the entity uses camelCase.","commonSituations":"Snake-case leak from raw SQL mindset; rename missing call sites; ordering by a computed field that exists on the type but isn't @Column; embedded/nested paths not fully qualified.","solutions":["Use the @Column property name (camelCase typically), not the DB column name.","For relations, add a join and order by the joined alias instead.","Update call sites when renaming any column used in order clauses.","Grep `order:` usages after column renames."],"exampleFix":"// before\nawait repo.find({ order: { created_at: 'DESC' } });\n\n// after\n@Entity()\nclass User { @Column() createdAt!: Date; }\nawait repo.find({ order: { createdAt: 'DESC' } });","handlingStrategy":"validation","validationCode":"function validateOrder<Entity>(meta: import('@n8n/typeorm').EntityMetadata<Entity>, order: Record<string, any>): void {\n  for (const key of Object.keys(order)) {\n    if (!meta.findColumnWithPropertyPath(key)) {\n      throw new Error(`order key ${key} is not a mapped column on ${meta.name}`);\n    }\n  }\n}\nvalidateOrder(connection.getMetadata(Entity), options.order ?? {});\nawait repo.find(options);","typeGuard":"function isOrderableKey<Entity>(meta: import('@n8n/typeorm').EntityMetadata<Entity>, key: string): boolean {\n  return !!meta.findColumnWithPropertyPath(key);\n}","tryCatchPattern":null,"preventionTips":["Use property names (camelCase) in order, not DB column names.","For relation columns, join first and order by the joined alias.","Type order keys as keyof Entity.","Grep `order:` when renaming columns."],"tags":["typeorm","find-options","order","metadata"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}