Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Admin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
osuny
Admin
Commits
060537ca
Unverified
Commit
060537ca
authored
3 months ago
by
Arnaud Levy
Committed by
GitHub
3 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Order by slug (#2511)
parent
0e57af99
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/models/concerns/localizable_order_by_slug_scope.rb
+29
-0
29 additions, 0 deletions
app/models/concerns/localizable_order_by_slug_scope.rb
app/models/education/program.rb
+1
-1
1 addition, 1 deletion
app/models/education/program.rb
with
30 additions
and
1 deletion
app/models/concerns/localizable_order_by_slug_scope.rb
0 → 100644
+
29
−
0
View file @
060537ca
module
LocalizableOrderBySlugScope
extend
ActiveSupport
::
Concern
# Cf LocalizableOrderByNameScope
included
do
scope
:ordered
,
->
(
language
)
{
localization_name_select
=
<<-
SQL
COALESCE(
MAX(CASE WHEN localizations.language_id = '
#{
language
.
id
}
' THEN TRIM(LOWER(UNACCENT(localizations.slug))) END),
MAX(TRIM(LOWER(UNACCENT(localizations.slug)))) FILTER (WHERE localizations.rank = 1)
) AS localization_slug
SQL
joins
(
sanitize_sql_array
([
<<-
SQL
LEFT JOIN (
SELECT
localizations.*,
ROW_NUMBER() OVER(PARTITION BY localizations.about_id ORDER BY localizations.created_at ASC) as rank
FROM
#{
table_name
.
singularize
}
_localizations as localizations
) localizations ON
#{
table_name
}
.id = localizations.about_id
SQL
]))
.
select
(
"
#{
table_name
}
.*"
,
localization_name_select
)
.
group
(
"
#{
table_name
}
.id"
)
.
order
(
"localization_slug ASC"
)
}
end
end
This diff is collapsed.
Click to expand it.
app/models/education/program.rb
+
1
−
1
View file @
060537ca
...
...
@@ -30,7 +30,7 @@ class Education::Program < ApplicationRecord
include
AsIndirectObject
include
Filterable
include
Localizable
include
LocalizableOrderBy
Name
Scope
include
LocalizableOrderBy
Slug
Scope
include
Sanitizable
include
WebsitesLinkable
include
WithAlumni
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment