-
-
Notifications
You must be signed in to change notification settings - Fork 190
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
Introduce Order enum #389
Introduce Order enum #389
Conversation
Yeah, looks good to me :-) |
@@ -155,16 +155,19 @@ public function getWhereExpression() | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future, we would have @return array<string, Order>
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I should use array<string, string|Order>
right now so that people start adapting their code, even if in practice we don't break BC and stay with array<string, string>
? 🤔 either that or introducing a new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should provide a way to opt into the future behavior of this method. We could do so by adding a boolean flag (meh) or by adding a new method and deprecating this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll try to find a new name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is no setter, I went with just orderings()
src/Order.php
Outdated
case ASC = 'ASC'; | ||
case DESC = 'DESC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
case ASC = 'ASC'; | |
case DESC = 'DESC'; | |
case Ascending = 'ASC'; | |
case Descending = 'DESC'; |
WDYT?
* | ||
* @param array<string, string> $orderings | ||
* @param array<string, string|Order> $orderings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The types of the constructor signature have to be adjusted as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
src/Criteria.php
Outdated
return $ordering; | ||
} | ||
|
||
return strtoupper($ordering) === Order::ASC->value ? Order::ASC : Order::DESC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trigger a deprecation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we give the ORM a chance to upgrade first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to wait for that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let me add that deprecation layer then.
* @see Criteria::ASC | ||
* @see Criteria::DESC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecate the constants?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tests/BaseArrayCollectionTest.php
Outdated
@@ -331,7 +332,7 @@ public function testMatchingWithSortingPreserveKeys(): void | |||
'object1' => $object1, | |||
], | |||
$collection | |||
->matching(new Criteria(null, ['sortField' => Criteria::ASC])) | |||
->matching(new Criteria(null, ['sortField' => Order::ASC])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By simply changing the tests, you lose coverage for the old way of using this API. Codecov rightfully complains about that.
2c70d32
to
6b56e71
Compare
I guess this will then also be the way to order collections?: #[ORM\OneToMany(...)
#[ORM\OrderBy(value: ['foo' => Order::Ascending])
private Collection $bar; |
Yes 👍 |
The plan is to ultimately use it and only it dealing with Criteria::$orderings.
Ping @derrabus 🙏 |
Which branch/version of the docs should I edit? |
I think it depends, we have to look at the code, and see if the new names are passed as is or if some kind of translation/method signature changes are required. BTW, why are you mentioning DBAL? It does not depend on collections, does it? |
I'm talking about the docs, not the code! So should I replace all 'ASC' with the new |
I know, and please don't shout!
That's an SQL query builder. This has nothing to do with collections whatsoever.
Maybe, wait a bit, we have to evaluate which ones are going to be OK, and which ones require a breaking change. For instance consider this: class ClassFromTheORM
{
public function methodFromTheOrm(string $ordering)
{
Criteria::orderBy(['field' => $ordering);
}
} Can't recommend |
Sorry :-)
I thought this is what this PR addresses?! - Moving from |
What you just said + referring to I don't think you will be able to find similar stuff in the DBAL. |
OK, gotcha.
|
You should IMO wait until we at least:
|
We just upgraded doctrine packages. Changing Problem is that we used this everywhere where QueryBuilder is involved (a lot), and it was quite disappointing seeing that this is not going to work. We go from this:
to this:
Yes, I do understand that Collections & ORM are separate, but ORM relays on Collections as dependency. |
Neither a) nor b) is planned at the moment. That being said, this is the wrong repository for this discussion. |
The plan is to ultimately use when dealing with
Criteria::$orderings