When I try to select a Person with .find()
it does a select as it should. But the select has several fields in it i did not declare like like this. Example:
Field:
...
@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;
...
}
Info: The Entity was generated with TypeOrm-Model-Generator
The select looks like this in the log:
...
`person`.`mailBlogYnKeyTypKz` AS `person_mailBlogYnKeyTypKz`
...
Here the code and the Connection setup:
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));
Here is the Person.ts
and the complete SQL statement and some data about my table person.
Select-Problem.zip
Yes, its a Issue of the generator. (See here: Typeorm Issue 1253 )
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn()
mail_blog_yn:lov_jn_kz;
should be:
@ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
@JoinColumn({ name: "mail_blog_yn" })
mail_blog_yn:lov_jn_kz;
This fixes the issue but doing by hand is not an option for me, so typeorm-model-generator should definitely fix this.
Keep track of this issue on typeorm-model-generator: Issue #13