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
Inconsistent Single Parameter Search Behavior with "Record<string, unknown>" type #4755
Comments
What if you type it this way? @Property({ type: 'json' })
body?: Record<string, unknown>; I guess you are using ts-morph? |
When adding "@Property({ type: 'json' })", the issue worsens, as the search returns "null" even when "request.body" only contains the "ip" parameter. However, using just "@Property()", I get a positive result if "request.body" has only one parameter in the database; but if there's more than one, it doesn't return any result. In summary, with only "@Property()" the behavior is bad, but with "@Property({ type: 'json' })" it deteriorates even further. It's important to note that I'm using the "TsMorphMetadataProvider" for metadata provisioning. |
{
"properties": {
"body": {
"name": "body",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "Record<string, unknown>",
"array": false,
"runtimeType": "Record<string, unknown>",
"optional": true
},
"headers": {
"name": "headers",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "Record<string, unknown>",
"array": false,
"runtimeType": "Record<string, unknown>",
"optional": true
},
"method": {
"name": "method",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "string",
"array": false,
"runtimeType": "string"
},
"url": {
"name": "url",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "string",
"array": false,
"runtimeType": "string"
}
},
"props": [
{
"name": "body",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "Record<string, unknown>",
"array": false,
"runtimeType": "Record<string, unknown>",
"optional": true
},
{
"name": "headers",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "Record<string, unknown>",
"array": false,
"runtimeType": "Record<string, unknown>",
"optional": true
},
{
"name": "method",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "string",
"array": false,
"runtimeType": "string"
},
{
"name": "url",
"kind": "scalar",
"getter": false,
"setter": false,
"type": "string",
"array": false,
"runtimeType": "string"
}
]
} Here's a summary of the JSON generated in the "temp" folder. The file is named "ApiIpApiRequest.js.json". I hope this information proves helpful. Note: This is the JSON generated using "@Property()". |
Describe the bug
There's an issue with the search functions in MikroOrm. When a parameter is of type "Record<string, unknown>", the database search demands an exact object match, rather than allowing searches based on a single parameter.
Example
If there's a document in the database with its only saved field coming from "request.body" being the "ip" parameter, and the search is based solely on matches for "request.body.ip", then the result is successful. However, if "request.body" has multiple parameters and the search is limited to finding matches in "request.body.ip", it will always return "null", even if there is a document with that specific "ip" in the database. Essentially, when the parameter type is "Record<string, unknown>", MikroOrm, for some reason, expects the search to match entirely with the stored document, preventing searches based on a single parameter.
It's worth noting that if all the data in "request.body" were typed, either through an "object" or an "Embeddable", then it would be possible to search using just one parameter.
Expected behavior
It's expected that even if a parameter is of type "Record<string, unknown>", one should be able to search the database based on a single parameter rather than requiring an exact object match.
Additional context
I'm using the Mongo driver and version 6 of MikroOrm; however, the same issue occurs in version 5.
Versions
The text was updated successfully, but these errors were encountered: