-
-
Notifications
You must be signed in to change notification settings - Fork 834
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
Allow using callbacks with load
relations extender
#3116
Conversation
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.
Overall I like this, but I have a few concerns:
- we're mixing arrays with integer-indexed and string-index elements. This feels very off to me, but I'm not sure I have a better idea: the alternative would be separate extender methods, but that feels a bit clunky and confusing.
- Although the type system won't freak out, if the request is not given, the callback could fail with a null pointer exception.
More generally though, the load
system is starting to feel pretty convoluted and complicated. In this case, it feels like it should be done through the tag model's withStateFor
method. Maybe that should somehow be baked into the relation? But I also wonder if there's some way we can determine what we need to explicitly load based on include
information without having to specify this directly at all.
# Conflicts: # src/Api/Controller/ListGroupsController.php
Been thinking about this. I have tweaked the current system to keep This is how it looks like in tags now, the reason we tap into the (new Extend\ApiController(ListDiscussionsController::class)
->loadWhere('tags', function ($query, $request, $relations) {
if ($request && in_array('tags.state', $relations, true)) {
$query->withStateFor(RequestUtil::getActor($request));
}
}),
I don't see that being possible, apart from needing to eager load what is to be included in the JSON response, other models to eager load depend on what relations we access to use in the code logic. |
Needed for flarum/tags#149
Changes proposed in this pull request:
Some more complex relations can require eager loading with a callback, it is currently not possible, which is what this PR is for.
More explanation about the specific issue this helps solve in the related tags PR.
Reviewers should focus on:
This all needs to be backwards compatible of course, is it the case or am I missing something ?
Necessity
Confirmed
composer test
).