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
I am seeking all users named Chris, age 35. In reality, I will get all users named Chris, age is ignored. I'd expect one of two things to happen:
It should either perform the query with my age property by passing it directly into SQL (SELECT * FROM users WHERE name = 'Chris' AND age = 35, essentially)...
...or it should throw an error because I am using an undeclared property. The compiler should be aware that this field doesn't exist and could give me an error before I even ran the query.
In reality, it ignores keys that it doesn't recognize. The query that I think I'm making is not the one that is actually being made and nobody will catch it until a user or a test notices. This strikes me as somewhere between bug and feature request: it doesn't seem like a deliberate design decision but I'm not sure I'd call it broken, it strikes me as unimplemented behavior.
Part of the problem seems to be the types associated with where. Looking at the FindOneOptions interface, I see where defined:
I can get a compiler error if I explicitly define the argument ahead of time:
// This will upset the compiler if there is an undefined property!constwhere: FindConditions={name: 'Chris',age: 35};
But it seems to me that there's no point in where?: including FindOptions<Entity> since it will never infer that type, it will always infer the more permissive ObjectLiteral, which is basically any, but only as a way of ignoring things it doesn't recognize -- it'll just filter them out:
exportinterfaceObjectLiteral{[key: string]: any;}
This has bit me a few times and it's always surprising. Not only will it bite you if you're working with an undeclared property, it also won't prevent you from making typos in your queries, which is part of why I'm using TypeORM in the first place! I'm not sure what my recommendation here is but at the very least, I'd expect TypeORM to do something visible when it sees a property it doesn't recognize, not just silently eat keys.
Thanks for your help. I love the work you guys are doing, TypeORM is a fantastic project.
The text was updated successfully, but these errors were encountered:
Issue type:
[x] feature request
[x] bug report?
Database system/driver:
[x]
postgres
TypeORM version:
[x]
0.2.18
(or put your version here)Steps to reproduce or a small repository showing the problem:
Not sure if this is a feature request or a bug: I find the current behavior of
where
queries that reference undeclared properties very surprising.Given a simple model:
Note that
age
is commented out. The column exists in my database but it is not declared in my entity.Now given this query:
I am seeking all users named Chris, age 35. In reality, I will get all users named Chris, age is ignored. I'd expect one of two things to happen:
age
property by passing it directly into SQL (SELECT * FROM users WHERE name = 'Chris' AND age = 35
, essentially)...In reality, it ignores keys that it doesn't recognize. The query that I think I'm making is not the one that is actually being made and nobody will catch it until a user or a test notices. This strikes me as somewhere between bug and feature request: it doesn't seem like a deliberate design decision but I'm not sure I'd call it broken, it strikes me as unimplemented behavior.
Part of the problem seems to be the types associated with
where
. Looking at theFindOneOptions
interface, I seewhere
defined:I can get a compiler error if I explicitly define the argument ahead of time:
But it seems to me that there's no point in
where?:
includingFindOptions<Entity>
since it will never infer that type, it will always infer the more permissiveObjectLiteral
, which is basicallyany
, but only as a way of ignoring things it doesn't recognize -- it'll just filter them out:This has bit me a few times and it's always surprising. Not only will it bite you if you're working with an undeclared property, it also won't prevent you from making typos in your queries, which is part of why I'm using TypeORM in the first place! I'm not sure what my recommendation here is but at the very least, I'd expect TypeORM to do something visible when it sees a property it doesn't recognize, not just silently eat keys.
Thanks for your help. I love the work you guys are doing, TypeORM is a fantastic project.
The text was updated successfully, but these errors were encountered: