-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Multiple joins for reaction type counts #97
Conversation
… on reaction type name
@JFunu thank you for the contribution! What will happen if developer will add 2 joins with different types and without custom alias? $likeType = ReactionType::fromName('Like');
$dislikeType = ReactionType::fromName('Dislike');
Comment::query()
->joinReactionCounterOfType($likeType)
->joinReactionCounterOfType($dislikeType); I think it should work out of the box by default generating alias from the reaction name. And we could add extra public function scopeJoinReactionCounterOfType(
Builder $query,
ReactionTypeContract $reactionType,
?string $alias = null
): Builder { Then this code will join 2 counters with default aliases: Comment::query()
->joinReactionCounterOfType($likeType)
->joinReactionCounterOfType($dislikeType); And this one will join 2 counters with custom aliases: Comment::query()
->joinReactionCounterOfType($likeType, 'likesCounter')
->joinReactionCounterOfType($dislikeType, 'dislikesCounter'); I haven't decided how default alias will look like but it should depend of reaction name for sure, because they are unique. |
@antonkomarev . Thanks for the feedback. Have implemented the changes. |
Looks good! The only one things left to do - add test for join with custom |
Nevermind, I've merged it as is. I will add tests myself in next PR #102. @JFunu you are in Contributors list now! 🚀 |
Thanks @antonkomarev . My first contribution to open source. |
Welcome Aboard! 🥇 |
Hey @acidjazz ,
I fixed a use case of mine which I think might be beneficial to the community so I making this pull request.
The current implementation restricted you to only getting only one reaction type count on a reactant at a time with the
joinReactionCounterOfType
scope. This pr enables you chain multiple scopes of different reaction types to get all their respective counts at once.Kindly review and let me know if there are any modifications you will like me to make.