Kononnable / typeorm-model-generator

Generates models for TypeORM from existing database.
MIT License
1.51k stars 281 forks source link

typeorm-model-generators has missing properties #322

Closed wizardnet972 closed 3 years ago

wizardnet972 commented 3 years ago

When I run the generator on my database:

image

The files have missing properties. see the output files below.

sql

USE [test]
GO
/****** Object:  Table [dbo].[bar]    Script Date: 08/01/21 6:30:33 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[bar](
    [id] [int] NOT NULL,
 CONSTRAINT [PK_bar] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[baz]    Script Date: 08/01/21 6:30:33 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[baz](
    [id] [int] NOT NULL,
 CONSTRAINT [PK_baz] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[foo]    Script Date: 08/01/21 6:30:33 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[foo](
    [id] [int] NOT NULL,
 CONSTRAINT [PK_foo] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[foo]  WITH CHECK ADD  CONSTRAINT [FK_foo_bar] FOREIGN KEY([id])
REFERENCES [dbo].[bar] ([id])
GO
ALTER TABLE [dbo].[foo] CHECK CONSTRAINT [FK_foo_bar]
GO

Output files

bar.ts

import { Column, Entity, Index, JoinTable, ManyToMany } from "typeorm";
import { Baz } from "./baz";

@Index("PK_bar", ["id"], { unique: true })
@Entity("bar", { schema: "dbo" })
export class Bar {
  @Column("int", { primary: true, name: "id" })
  id: number;

  @ManyToMany(() => Baz, (baz) => baz.bars, { lazy: true })
  @JoinTable({
    name: "foo",
    joinColumns: [{ name: "id", referencedColumnName: "id" }],
    inverseJoinColumns: [{ name: "id", referencedColumnName: "id" }],
    schema: "dbo",
  })
  bazs: Promise<Baz[]>;
}

baz.ts

import { Column, Entity, Index } from "typeorm";

@Index("PK_baz", ["id"], { unique: true })
@Entity("baz", { schema: "dbo" })
export class Baz {
  @Column("int", { primary: true, name: "id" })
  id: number;
}

foo.ts

import {Column,Entity,Index,JoinColumn,OneToOne} from "typeorm";
import {Bar} from './bar'

@Index("PK_foo",["id",],{ unique:true })
@Entity("foo" ,{schema:"dbo" } )
export  class Foo {

@Column("int",{ primary:true,name:"id" })
id:number;

@OneToOne(()=>Bar,bar=>bar.foo,{ lazy:true })
@JoinColumn([{ name: "id", referencedColumnName: "id" },
])

:Promise<Bar>;

}

console output

There were some problems with model generation for table:  foo
SyntaxError: Declaration expected. (14:3)
  12 | @OneToOne(()=>Bar,bar=>bar.foo,{ lazy:true })
  13 | @JoinColumn([{ name: "id", referencedColumnName: "id" },
> 14 | ])
     |   ^
  15 |
  16 | :Promise<Bar>;
  17 |
    at e (C:\code\typeorm-test\node_modules\prettier\parser-typescript.js:1:322)
    at Object.parse (C:\code\typeorm-test\node_modules\prettier\parser-typescript.js:1:3072720)
    at Object.parse (C:\code\typeorm-test\node_modules\prettier\index.js:13625:19)
    at coreFormat (C:\code\typeorm-test\node_modules\prettier\index.js:14899:14)
    at format (C:\code\typeorm-test\node_modules\prettier\index.js:15131:14)
    at C:\code\typeorm-test\node_modules\prettier\index.js:57542:12
    at Object.format (C:\code\typeorm-test\node_modules\prettier\index.js:57562:12)
    at C:\code\typeorm-test\node_modules\typeorm-model-generator\dist\src\ModelGeneration.js:71:34
    at Array.forEach (<anonymous>)
    at generateModels (C:\code\typeorm-test\node_modules\typeorm-model-generator\dist\src\ModelGeneration.js:46:19) {
  loc: { start: { line: 14, column: 3 } },
  codeFrame: '\x1B[0m \x1B[90m 12 | \x1B[39m\x1B[33m@\x1B[39m\x1B[33mOneToOne\x1B[39m(()\x1B[33m=>\x1B[39m\x1B[33mBar\x1B[39m\x1B[33m,\x1B[39mbar\x1B[33m=>\x1B[39mbar\x1B[33m.\x1B[39mfoo\x1B[33m,\x1B[39m{ lazy\x1B[33m:\x1B[39m\x1B[36mtrue\x1B[39m })\x1B[0m\n' +
    '\x1B[0m \x1B[90m 13 | \x1B[39m\x1B[33m@\x1B[39m\x1B[33mJoinColumn\x1B[39m([{ name\x1B[33m:\x1B[39m \x1B[32m"id"\x1B[39m\x1B[33m,\x1B[39m referencedColumnName\x1B[33m:\x1B[39m \x1B[32m"id"\x1B[39m }\x1B[33m,\x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 14 | \x1B[39m])\x1B[0m\n' +
    '\x1B[0m \x1B[90m    | \x1B[39m  \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 15 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 16 | \x1B[39m\x1B[33m:\x1B[39m\x1B[33mPromise\x1B[39m\x1B[33m<\x1B[39m\x1B[33mBar\x1B[39m\x1B[33m>\x1B[39m\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 17 | \x1B[39m\x1B[0m'
}
There were some problems with model generation for table:  bar
SyntaxError: Identifier expected. (12:28)
  10 | id:number;
  11 |
> 12 | @OneToOne(()=>Foo,foo=>foo.,{ lazy:true })
     |                            ^
  13 |
  14 |
  15 | foo:Promise<Foo>;
    at e (C:\code\typeorm-test\node_modules\prettier\parser-typescript.js:1:322)
    at Object.parse (C:\code\typeorm-test\node_modules\prettier\parser-typescript.js:1:3072720)
    at Object.parse (C:\code\typeorm-test\node_modules\prettier\index.js:13625:19)
    at coreFormat (C:\code\typeorm-test\node_modules\prettier\index.js:14899:14)
    at format (C:\code\typeorm-test\node_modules\prettier\index.js:15131:14)
    at C:\code\typeorm-test\node_modules\prettier\index.js:57542:12
    at Object.format (C:\code\typeorm-test\node_modules\prettier\index.js:57562:12)
    at C:\code\typeorm-test\node_modules\typeorm-model-generator\dist\src\ModelGeneration.js:71:34
    at Array.forEach (<anonymous>)
    at generateModels (C:\code\typeorm-test\node_modules\typeorm-model-generator\dist\src\ModelGeneration.js:46:19) {
  loc: { start: { line: 12, column: 28 } },
  codeFrame: '\x1B[0m \x1B[90m 10 | \x1B[39mid\x1B[33m:\x1B[39mnumber\x1B[33m;\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 11 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 12 | \x1B[39m\x1B[33m@\x1B[39m\x1B[33mOneToOne\x1B[39m(()\x1B[33m=>\x1B[39m\x1B[33mFoo\x1B[39m\x1B[33m,\x1B[39mfoo\x1B[33m=>\x1B[39mfoo\x1B[33m.\x1B[39m\x1B[33m,\x1B[39m{ lazy\x1B[33m:\x1B[39m\x1B[36mtrue\x1B[39m })\x1B[0m\n' +
    '\x1B[0m \x1B[90m    | \x1B[39m                           \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 13 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 14 | \x1B[39m\x1B[0m\n' +
    '\x1B[0m \x1B[90m 15 | \x1B[39mfoo\x1B[33m:\x1B[39m\x1B[33mPromise\x1B[39m\x1B[33m<\x1B[39m\x1B[33mFoo\x1B[39m\x1B[33m>\x1B[39m\x1B[33m;\x1B[39m\x1B[0m'
}
[6:32:34 PM] Typeorm model classes created.
Kononnable commented 3 years ago

Which options are you passing to typeorm-model-generator? E.g. custom naming strategy might be important here.

wizardnet972 commented 3 years ago
[
  {
    "resultsPath": "C:\\code\\typeorm-test\\models",
    "pluralizeNames": true,
    "noConfigs": true,
    "convertCaseFile": "param",
    "convertCaseEntity": "pascal",
    "convertCaseProperty": "camel",
    "convertEol": "CRLF",
    "propertyVisibility": "none",
    "lazy": true,
    "activeRecord": false,
    "generateConstructor": false,
    "customNamingStrategyPath": "",
    "relationIds": false,
    "strictMode": "none",
    "skipSchema": false,
    "indexFile": true,
    "exportType": "named"
  }
]
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.