Select 的索引在 TypeORM 中名称错误
Select of indices with wrong names in TypeORM
当我尝试 select 具有 .find()
的人时,它会按预期执行 select。但是 select 中有几个字段我没有这样声明。例子:
字段:
...
@Index("mail_blog_yn",["mail_blog_yn",])
...
export class person {
...
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn()
mail_blog_yn:lov_jn_kz;
...
}
信息:实体是用 TypeOrm-Model-Generator
生成的
select 在日志中看起来像这样:
...
`person`.`mailBlogYnKeyTypKz` AS `person_mailBlogYnKeyTypKz`
...
这里是代码和连接设置:
typeorm.createConnection({
type: "mysql",
host: "localhost",
port: 3306,
username: Configuration.Database.user,
password: Configuration.Database.password,
database: Configuration.Database.database,
entities: [
...
person,
....
],
synchronize: false,
logging: true
}).then(connection => {
const modelRepository: typeorm.Repository<person> = connection.getRepository(person);
modelRepository.find({
"username" : 'x'
}).then(( persons: person[]) => {
console.log(JSON.stringify(persons));
});
}).catch(error => console.log(error));
这是 Person.ts
和完整的 SQL 声明以及一些关于我的 table 人的数据。
Select-Problem.zip
我现在有一个解决方法:
使用 TypeORM 中的 QueryBuilder 只允许我 select 我真正需要的值,并防止 orm selecting 所有值。
仍在等待真正的解决方案。
是的,这是生成器的问题。 (参见此处:Typeorm Issue 1253)
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn()
mail_blog_yn:lov_jn_kz;
应该是:
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn({ name: "mail_blog_yn" })
mail_blog_yn:lov_jn_kz;
这解决了这个问题,但手工操作对我来说不是一个选项,所以 typeorm-model-generator 绝对应该解决这个问题。
在 typeorm-model-generator 上跟踪此问题:Issue #13
当我尝试 select 具有 .find()
的人时,它会按预期执行 select。但是 select 中有几个字段我没有这样声明。例子:
字段:
...
@Index("mail_blog_yn",["mail_blog_yn",])
...
export class person {
...
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn()
mail_blog_yn:lov_jn_kz;
...
}
信息:实体是用 TypeOrm-Model-Generator
生成的select 在日志中看起来像这样:
...
`person`.`mailBlogYnKeyTypKz` AS `person_mailBlogYnKeyTypKz`
...
这里是代码和连接设置:
typeorm.createConnection({
type: "mysql",
host: "localhost",
port: 3306,
username: Configuration.Database.user,
password: Configuration.Database.password,
database: Configuration.Database.database,
entities: [
...
person,
....
],
synchronize: false,
logging: true
}).then(connection => {
const modelRepository: typeorm.Repository<person> = connection.getRepository(person);
modelRepository.find({
"username" : 'x'
}).then(( persons: person[]) => {
console.log(JSON.stringify(persons));
});
}).catch(error => console.log(error));
这是 Person.ts
和完整的 SQL 声明以及一些关于我的 table 人的数据。
Select-Problem.zip
我现在有一个解决方法:
使用 TypeORM 中的 QueryBuilder 只允许我 select 我真正需要的值,并防止 orm selecting 所有值。
仍在等待真正的解决方案。
是的,这是生成器的问题。 (参见此处:Typeorm Issue 1253)
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn()
mail_blog_yn:lov_jn_kz;
应该是:
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn({ name: "mail_blog_yn" })
mail_blog_yn:lov_jn_kz;
这解决了这个问题,但手工操作对我来说不是一个选项,所以 typeorm-model-generator 绝对应该解决这个问题。
在 typeorm-model-generator 上跟踪此问题:Issue #13