-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
Filter object #506
base: main
Are you sure you want to change the base?
Filter object #506
Conversation
New API is not in IRepository intentionally, so it could be released before next major. Separate issue should be created for that. Note to self:
|
Also I am not sure whether it would be more helpful to add methods chaining or change ordering interface to something like |
Hi, first of all - thanks for exploring this and trying to come up with solution. 👍 I would like to have something like this but TBH this is a low priority for me now. The solution should bring something other than "new query syntax" here. Specifically I'm thinking about:
I was already thinking about something like IExpression but never finished the idea to some meaninful concept. If this works for you nicely, definitely keep using it in your code, probably the missing part is the autoconversion to array condition but I'd say it's quite usable without that :) |
Currently it requires function to be
Yeah, it would be useful. I will try to come up with same api that would be compatible with that feature. Some more complex example would be helpful. |
Also, I'm thinking about reverting the way what you do here:
Just wanna let you know what I personally expect of this project - not asking you to do it. This definitely needs more exploration. Lately I find the proper API (for new dbal & orm features) the most difficult ask. |
Let's say this is working proof of concept. Whether it uses objects or arrays under the hood doesn't matter :) |
Naming is not much important now. The important thing is e.g. composing multiple branches of condition - like you generate the conditions in different places and merge them later via AND.
The underlying change may shape the resulting API much more than we can expect. This is the reason I see no hurry meting this when it may be a nice user-defined API. |
So instead of
Something like this?
I am sure we could eventualy mix it together, but I see no simple way how could be building subnodes and then the root node supported by phpstan and phpstorm plugins. |
I was playing with that approach last few weeks and imho it could look like this: $find->by(
$find->notEqual(
$find->countAggregate('triggers->id'),
0,
),
);
Composing multiple branches of condition should be fairly easy :) For and/or conditions I see two viable approaches:
$find->by($find->or(static function (FindFilter $scope) use ($guardedObjects): void {
foreach ($guardedObjects as $code => $object) {
$scope->by(
$scope->equal('guardedObjectCode', (string) $code)
);
if ($object !== null) {
$scope->by(
$scope->equal('guardedObject', $object)
);
}
}
}));
$orConditions = [];
foreach ($guardedObjects as $code => $object) {
$orConditions[] = $find->equal('guardedObjectCode', (string) $code);
if ($object !== null) {
$orConditions[] = $find->equal('guardedObject', $object);
}
}
$find->by($find->or($orConditions)); |
Build conditions for
findBy()
,orderBy()
andlimitBy()
via objectExample usage: (check tests for more)
Pros:
Cons: