Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select of Person with wrong index-name #1253

Closed
Joniras opened this issue Nov 28, 2017 · 6 comments
Closed

Select of Person with wrong index-name #1253

Joniras opened this issue Nov 28, 2017 · 6 comments

Comments

@Joniras
Copy link

Joniras commented Nov 28, 2017

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 the Person.ts and the complete sql statement and some data about my table persons.
Select-Problem.zip

@pleerock
Copy link
Member

Its not really pleasure to figure out things when you have mail_blog_yn namings. Please create a minimal reproduction git repo with clean models without any generator applied and make a concrete indication of the problem you have.

@Joniras
Copy link
Author

Joniras commented Dec 1, 2017

But i have to use the generator, if i would not use the generator in my project, i would have to create over 30 Models by Hand. Thats not very convenient for me.

But I have a Workaround for now:

Using the QueryBuilder allows me to only select the values i really need and prevents the orm from selecting all values.

Still waiting for a real solution approach

@pleerock
Copy link
Member

pleerock commented Dec 1, 2017

Its still not clear for me what issue you have.

@Joniras
Copy link
Author

Joniras commented Dec 2, 2017

I assume the issue is that the select is wrong done.
As seen here:

...
`person`.`mailBlogYnKeyTypKz` AS `person_mailBlogYnKeyTypKz`
...

The attribute name is different here:

    @ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
    @JoinColumn()
    mail_blog_yn:lov_jn_kz;

Dosnt make sense for me at all.
Where does this name: person.mailBlogYnKeyTypKz come from and why is it generated like this ?

@pleerock
Copy link
Member

pleerock commented Dec 4, 2017

okay, lets me ask you one thing, how your column is called in the database? If its called mail_blog_yn then you need to provide a custom column name inside @JoinColumn this way:

    @ManyToOne(type=>lov_jn_kz, mail_blog_yn=>mail_blog_yn.persons4)
    @JoinColumn({ name: "mail_blog_yn" })
    mail_blog_yn:lov_jn_kz;

And if that solves your issue then report issue in generator, because its generator issue.

@Joniras
Copy link
Author

Joniras commented Dec 5, 2017

Yes, appearently its a issue of the generator.

Thanks for the help, i will create an issue there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants