Browse Source

fix(cli): Create new instance of entity before saving to db in generated Entity (#3623)

Alexander Berger 6 months ago
parent
commit
8a2e679749
1 changed files with 2 additions and 1 deletions
  1. 2 1
      packages/cli/src/commands/add/service/add-service.ts

+ 2 - 1
packages/cli/src/commands/add/service/add-service.ts

@@ -280,7 +280,8 @@ function customizeCreateMethod(serviceClassDeclaration: ClassDeclaration, entity
                             });`);
             } else {
                 writer.writeLine(
-                    `const newEntity = await this.connection.getRepository(ctx, ${entityRef.name}).save(input);`,
+                    `const newEntityInstance = new ${entityRef.name}(input);
+                    const newEntity = await this.connection.getRepository(ctx, ${entityRef.name}).save(newEntityInstance);`,
                 );
             }
             if (entityRef.hasCustomFields()) {