You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Steps to reproduce or a small repository showing the problem:
I know I should provide User class itself to findOne, but I found myself using obj.constructor to save an entity. Looks like TypeScript skips the type validation of FindConditions<T> because T is an {} I think. Nevertheless it shouldn't return an entity that does not match the FindConditions provided. Correct me if I'm wrong. Thanks!
import {Entity, PrimaryGeneratedColumn, Column, getManager, createConnection} from "typeorm";
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
}
async function main() {
await createConnection(); // create connection somehow
var search = {fieldNotExists: "1"}; // field does not exists on User class
var user = new User();
var r = await getRepository<User>(user.constructor).findOne(search);
console.log(r); // returns first entity of table instead of undefined
}
main();
The text was updated successfully, but these errors were encountered:
carlosdubus
changed the title
getManager().findOne(entity.constructor) returns an entity even if FindConditions don't exists
repository.findOne(entity.constructor) returns an entity even if FindConditions don't exists
Jan 18, 2019
Duplicate of #3416. We just discuss about this problem. Unknown fields are stripped from query so result condition is {} and it is returned first entity in table.
Issue type:
[x] question
[x] bug report
Database system/driver:
[x]
mysql
/mariadb
TypeORM version:
[x]
latest
Steps to reproduce or a small repository showing the problem:
I know I should provide User class itself to findOne, but I found myself using obj.constructor to save an entity. Looks like TypeScript skips the type validation of FindConditions<T> because T is an {} I think. Nevertheless it shouldn't return an entity that does not match the FindConditions provided. Correct me if I'm wrong. Thanks!
The text was updated successfully, but these errors were encountered: