Skip to content
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

Complex orderBy conflicts when containing floats #1067

Closed
yanniz0r opened this issue Nov 10, 2020 · 1 comment
Closed

Complex orderBy conflicts when containing floats #1067

yanniz0r opened this issue Nov 10, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@yanniz0r
Copy link

Describe the bug

As I was trying to build distance based filtering, I added a rather complex orderBy statement which worked pretty decent at first. It looks like this:

query.orderBy({[`(point(location_latitude, location_longitude) <@> point(${location.latitude},${location.latitude}))`]: 'ASC'});

Using the code above with a location like { latitude: 53, longitude: 9 } results in a correct and expecected query of the following form:

select "e0".* from "events" as "e0" left join "venues" as "e1" on "e0"."venue_id" = "e1"."id" order by (point(location_latitude, location_longitude) <@> point(53, 53)) asc limit 10

However, when using floating point numbers (eg. { latitude: 53.46, longitude: 9.90 }), I get an error which says

ORDER BY position 46 is not in select list

Taking a closer look at the generated query shows the reason for this error, as the query by statement has an unexpected shape:

select "e0".* from "events" as "e0" left join "venues" as "e1" on "e0"."venue_id" = "e1"."id" order by 46, 53 asc limit 10

To Reproduce
Steps to reproduce the behavior:

  1. Setup a project with Mikro ORM
  2. Call the orderBy function of the query builder as seen above with floating point numbers

Expected behavior
The order by part of the query should look the same as if it contains integers.

Additional context
I'm usig Postgres, the Error occurred also in version 4.0.2.´

It's 100% possible that I'm missing something here, but from my current understanding, using floats should not change the generated query in this way. If there's anything that I can do to further assist this issue let me know :)

Versions

Dependency Version
node 14.4.0
typescript 3.9.7
mikro-orm 4.2.3
pg 8.3.0
@B4nan
Copy link
Member

B4nan commented Nov 10, 2020

The dot in float number is causing the troubles here, as it is considered as a dot between alias and property name (like a.book). When processing orderBy clause, custom expressions like this were supported more as a side effect rather than on purpose, at least the code looks like so :D

@B4nan B4nan added the bug Something isn't working label Nov 10, 2020
@B4nan B4nan closed this as completed in 11e8c56 Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants