-
-
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
Order of multiple nested orderBy params #2010
Comments
I'd probably rather go with supporting array too instead of the dot notation, so you can do this: orderBy: [
{ address: { city: 'ASC' } },
{ name: 'ASC' },
{ address: { street: 'ASC' } },
] |
@B4nan can you estimate how big of a change that would be? If it's not to big and does not involve a lot of knowledge about the codebase, i could go ahead and open a PR. Maybe you could also point me in the direction where i would need to implement this change. |
I guess it could be rather easy, the functional bit will be in Mostly this method is what you have to change: It might as well be as simple as looping over that array instead of using QB tests are here: https://github.com/mikro-orm/mikro-orm/blob/master/tests/QueryBuilder.test.ts |
Just to tack onto this, as discussed on Slack it would be really cool to support strict typing here too. Thanks! |
`FindOptions.orderBy` parameter is now strictly typed. It also allows passing an array of objects instead of just a single object. ```ts const books = await em.find(Book, {}, { orderBy: [ { title: 1 }, { author: { name: -1 } }, ], }); ``` Closes #2010
`FindOptions.orderBy` parameter is now strictly typed. It also allows passing an array of objects instead of just a single object. ```ts const books = await em.find(Book, {}, { orderBy: [ { title: 1 }, { author: { name: -1 } }, ], }); ``` Closes #2010
Is your feature request related to a problem? Please describe.
Lets say if have an entity
Address { city: string; street: string; }
and
Customer { name: string; address: Address; }
and i query the customers entity and want to order by address.city first, then name and then address.street, that is currently not possible as far as i am aware. The orderBy Param would look something like this:
which is not possible because of the duplicate address key.
Describe the solution you'd like
Is there a solution for this which i am not aware of and if not, is there a chance to add something to make this possible? An idea without introducing a breaking change would be to automatically parse keys like "address.city".
Or you could optionally allow for an array or object instead of the QueryOrder, where you could specify the order by a number. something like
The text was updated successfully, but these errors were encountered: