-
-
Notifications
You must be signed in to change notification settings - Fork 499
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
raw() in orderBy in decorator throws error: column [raw] does not exist #5277
Comments
I'm afraid supporting this properly might be a wontfix, the way things are currently designed allows only a single use of a raw fragment as a key, so even if we fix this, it would only work once per the whole app context, not just fork based. I'll first try to fix the single usage, and we could add a callback signature for the edit: Maybe there is another way around, we could allow marking raw fragments as global and those would be never removed from the map, something like But there is an alternative approach you can use right now - with a formula property for the length that you can use for ordering: @Formula(a => `length(${a}.text)`)
textLength!: number;
// ...
@OneToMany({
entity: () => EntityB, mappedBy: (entityB: EntityB) => entityB.entityA,
orderBy: {
textLength: "asc"
}
})
orderedEntityBs: Collection<EntityB> = new Collection<EntityB>(this); |
I'm wondering why I like the |
|
Describe the bug
When using the
raw()
helper function in the orderBy field of the decorator, it generates an invalid sql which results in an error:column [raw] does not exist
.Example:
Then trying to query:
throws error:
InvalidFieldNameException: select `e0`.*, `o1`.`id` as `o1__id`, `o1`.`text` as `o1__text`, `o1`.`entity_a_id` as `o1__entity_a_id` from `entity_a` as `e0` left join `entity_b` as `o1` on `e0`.`id` = `o1`.`entity_a_id` order by `o1`.`[raw]` asc - SQLITE_ERROR: no such column: o1.[raw]
Meanwhile using the same raw() in the orderBy of find functions works perfectly fine as seen in repro.
Note that
expr
in MikroORM v5 didn't have the same problem.Reproduction
Repro
What driver are you using?
@mikro-orm/sqlite
MikroORM version
6.1.6-dev.1
Node.js version
v18.18.0
Operating system
Linux
Validations
The text was updated successfully, but these errors were encountered: