Replies: 9 comments
-
imo this would need a custom query change, what's your dbms? |
Beta Was this translation helpful? Give feedback.
-
@soyuka, i use MariaDB 10 |
Beta Was this translation helpful? Give feedback.
-
why don't you use the |
Beta Was this translation helpful? Give feedback.
-
Because i need FLOATing point values – in project exists many different currencies (regular ones and crypto too) that have different precision. When i switch to DECIMAL, there are many problems appearing: need conversion every time between float/string in code before using bcmath; some currencies with scale as 10 numbers are too low (like btc) for PHP and i need to patch apiplatform to cast it into string without scientific form; my unit tests are failing because of "1/3 floating problem"; and so on.
@soyuka, casting in mysql order query seems enough. At least, i can run load tests and profile what happens (-: Can you show me how/where to configure/patch apiplatform to do so only for one fiend of one resource? |
Beta Was this translation helpful? Give feedback.
-
You may create your own Filter (see https://api-platform.com/docs/core/filters/#creating-custom-filters) by taking example on https://github.com/api-platform/core/blob/master/src/Bridge/Doctrine/Orm/Filter/OrderFilter.php |
Beta Was this translation helpful? Give feedback.
-
@trogwarz Did you find a solution ? Can you share it with us ? |
Beta Was this translation helpful? Give feedback.
-
@OlivierFromLille, well.. workarouding this with string/cast/customfilter-solution took too much time and raised complexity too high (or i don't have simple idea how to do it). So.. i gave up and made two decisions:
In general, it fixes problem and solution is simple in code support. But.. feels ugly (-: |
Beta Was this translation helpful? Give feedback.
-
Thanks @trogwarz In a custom filter :
So, here an example of "extreme" sorted versions (in parenthesis, the calcul to show how it looks) :
`<?php use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\AbstractContextAwareFilter; /**
Note that SUBSTRING_INDEX is not in doctrine by default so I used https://github.com/beberlei/DoctrineExtensions |
Beta Was this translation helpful? Give feedback.
-
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Beta Was this translation helpful? Give feedback.
-
What is best way to sort by decimal value?
For example, i need to do this request
GET api.example.com/orders.jsonld?order[price]=desc
and it returns prices in this order: 1, 2, 21, 22, 23, 3, 4, 47, 5, ...My prices stored as strings (because i use many operations with them as money). But i want to sort them as numbers.
Any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions