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

Empty string in findOne #2990

Closed
dkirchhof opened this issue Oct 25, 2018 · 2 comments
Closed

Empty string in findOne #2990

dkirchhof opened this issue Oct 25, 2018 · 2 comments

Comments

@dkirchhof
Copy link

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[x] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.7 (or put your version here)

Steps to reproduce or a small repository showing the problem:

If i pass an empty string to the findOne method, it will ignore the param and doesn't use a where clause in the query.

example:

  • repo.findOne("foo") returns SELECT ... FROM ... WHERE id = ? -- PARAMETERS: ["foo"]
  • repo.findOne("") returns SELECT ... FROM ... (here without WHERE and PARAMETERS)

Is it intended? Probably it's not very usefull to set an empty string as a primary key for one of the entities, but in some cases, this behaviour will produce heavy problems (eg. passing an empty string by mistake to the server, typeorm will return the first entity of the table).

@riadhriadh
Copy link

example

findOnebyName(name: string): Promise<any> {
    return (await this.footRepository.find({ name }))[0];
  }

@imnotjames
Copy link
Contributor

Duplicate of #3416

@imnotjames imnotjames marked this as a duplicate of #3416 Oct 12, 2020
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

3 participants