Skip to content

Fix TypeORM metadata error on GradeName save - #162

Merged
buzz-code merged 1 commit into
mainfrom
claude/typeorm-entity-metadata-wxfrg7
Aug 31, 2026
Merged

buzz-code merged 1 commit into
mainfrom
claude/typeorm-entity-metadata-wxfrg7

Conversation

@buzz-code

Copy link
Copy Markdown
Owner

Problem

Creating/updating a grade_name threw a 500:

TypeORMError: Entity metadata for KlassType#teacher was not found. Check if you specified a correct entity object and if it's connected in the connection options.

Root cause

GradeName.fillFields() built its ephemeral DataSource with only [KlassType]. But KlassType has decorator-declared ManyToOne relations to Teacher and User, so TypeORM needs metadata for those related entities too when building the DataSource — passing KlassType alone left teacher's target entity metadata unresolved.

Fix

Include Teacher and User in the getDataSource(...) call, matching the pattern already used elsewhere (Klass.entity.ts, StudentKlass.entity.ts, Lesson.entity.ts, etc.).

Testing

  • npx tsc --noEmit — clean
  • npx jest — 114 suites / 1013 tests passed

Generated by Claude Code

GradeName.fillFields() built its ephemeral DataSource with only
[KlassType], but KlassType has ManyToOne relations to Teacher and
User declared via decorators. TypeORM needs metadata for those
related entities too, so building the DataSource with KlassType
alone threw 'Entity metadata for KlassType#teacher was not found.'

Include Teacher and User, matching the pattern already used by
Klass.entity.ts, StudentKlass.entity.ts and others.
@buzz-code
buzz-code merged commit f46fca0 into main Aug 31, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants