Skip to content

Prevent duplicate left joins in translation order queries. #454

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

shaunluedeke
Copy link

@shaunluedeke shaunluedeke commented Jun 4, 2025

This pull request modifies the scopeOrderByTranslation method in src/Translatable/Traits/Scopes.php to improve its functionality and flexibility by adding support for specifying a locale and optimizing the query logic.

Enhancements to scopeOrderByTranslation:

  • Added an optional ?string $local = null parameter to allow specifying a locale directly when ordering translations. If not provided, the method defaults to using the current locale.
  • Optimized the query logic by checking for existing LEFT JOIN clauses on the translations table before adding a new one, preventing redundant joins and improving query efficiency.
  • Removed redundant variables ($localeKey and $keyName) and streamlined the join logic to use class methods directly for retrieving keys and table names.

@shaunluedeke
Copy link
Author

fixes #193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant