Nulls Last and Nulls First Parameters Sorting#769
Nulls Last and Nulls First Parameters Sorting#769SepehrBazyar wants to merge 25 commits intoormar-orm:masterfrom
Conversation
Codecov Report
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## master #769 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 192 192
Lines 16057 16113 +56
=========================================
+ Hits 16057 16113 +56
|
|
Hi @collerek |
|
Since both options are mutually exclusive (you cannot have nulls both last and first at the same time) that should be a single option, something like: That would also greatly simplify the conditions in the code as you have explicit value to handle. |
| return result + f" nulls {self.nulls}" # pragma: no cover | ||
|
|
||
| condition: str = "not" if self.nulls == "first" else "" # pragma: no cover | ||
| return f"{field_name} is {condition} null, {result}" # pragma: no cover |
There was a problem hiding this comment.
If you split this condition into two the result now lacks prefix and will not work with nested models.
You would have in example {prefix}{table_name}.{field_name} is null, {field_name} {self.direction}.
The second field_name does not have the prefix.
There was a problem hiding this comment.
If you split this condition into two the result now lacks prefix and will not work with nested models.
You would have in example
{prefix}{table_name}.{field_name} is null, {field_name} {self.direction}.The second field_name does not have the prefix.
Of course, I must mention that without this case, the test related to nested models will also pass correctly. Can you give an example of a possible error that may occur? Thanks
There was a problem hiding this comment.
When you have a parent model with two relations to the child model. So like items with created_by and modified_by that lead to the same User model. Each of those relations in joins has to have different prefixes as otherwise, you would have ambiguous column names.
| return self._select_operator(op="isnull", other=other) | ||
|
|
||
| def asc(self) -> OrderAction: | ||
| def asc(self, nulls_ordering: Optional[NullsOrdering] = None) -> OrderAction: |
There was a problem hiding this comment.
You should also be able to pass this param in order_by in queryset and querysetproxy for related models.
There was a problem hiding this comment.
You should also be able to pass this param in
order_byin queryset and querysetproxy for related models.
I do not understand this
How to determine this amount in order_by() and without asc() or desc()?
There was a problem hiding this comment.
In order by you can pass OrderActions or strings too. If you pass sort_order it's ascending, if you pass -sort_order it's descending. For nested models double underscore is required so like main_model_relation_field__child_model_field. It also supports putting a - before nested related model fields and then it's descending. The logic is starting in order_by where OrderActions are created from strings.
No description provided.