-
-
Notifications
You must be signed in to change notification settings - Fork 610
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When using an orderBy that includes a column in a relationship that is not part of the populate array, I'm getting an error like no such column: m1.name. The relationship in the orderBy is 3 levels deep (parent -> child -> grandchild) but the populate only includes the second level (parent -> child).
Example:
orm.em.find(
Equipment,
{},
{
populate: ['model'],
orderBy: { model: { manufacturer: { name: QueryOrder.ASC } } }
}
)
The table alias that is generated is the 2nd level relationship, not the 3rd level as expected (in addition to also including the correct alias). The generated sql from my repoduction repo looks like this:
select `e0`.*, `m1`.`id` as `m1__id`, `m1`.`model_name` as `m1__model_name`, `m1`.`manufacturer_id` as `m1__manufacturer_id` from `equipment` as `e0` left join `model` as `m1` on `e0`.`model_id` = `m1`.`id` left join `manufacturer` as `m2` on `m1`.`manufacturer_id` = `m2`.`id` order by `m2`.`name` asc, `m1`.`name` asc
Where I would expect it to look like this:
select `e0`.*, `m1`.`id` as `m1__id`, `m1`.`model_name` as `m1__model_name`, `m1`.`manufacturer_id` as `m1__manufacturer_id` from `equipment` as `e0` left join `model` as `m1` on `e0`.`model_id` = `m1`.`id` left join `manufacturer` as `m2` on `m1`.`manufacturer_id` = `m2`.`id` order by `m2`.`name` asc
Reproduction
https://github.com/bhdouglass/mikro-orm-reproduction
What driver are you using?
@mikro-orm/postgresql
MikroORM version
6.4.16
Node.js version
20.13
Operating system
Linux
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working