-
Notifications
You must be signed in to change notification settings - Fork 164
add multi-field scoping for slugs #274
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
Changes from 5 commits
01ef884
1e44a59
b283822
47ff69e
6013188
6486936
09a381d
868af28
65fc38e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,6 +193,26 @@ class Employee | |
| end | ||
| ``` | ||
|
|
||
| Sometimes, system constraints prevent using relation-based scoping. When this happens, you can scope slugs using multiple fields, addressing needs like database structure or performance issues. | ||
|
|
||
| Here's a quick setup for multi-field scoping: | ||
|
|
||
| ```ruby | ||
| class Employee | ||
| include Mongoid::Document | ||
| include Mongoid::Slug | ||
|
|
||
| field :name | ||
| field :company_id | ||
| field :department_id | ||
|
|
||
| # Scope slug uniqueness by a combination of company and department | ||
| slug :name, scope: %i[company_id department_id] | ||
| end | ||
| ``` | ||
|
|
||
| Note: this approach creates multiple indexes, differing from single-field scoping, and impacting database performance and storage. | ||
|
||
|
|
||
| ### Slug Max Length | ||
|
|
||
| MongoDB [featureCompatibilityVersion](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#std-label-view-fcv) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,6 @@ | |
|
|
||
| module Mongoid # :nodoc: | ||
| module Slug | ||
| VERSION = '7.0.0' | ||
| VERSION = '7.1.0' | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class PageWithCategories | ||
| include Mongoid::Document | ||
| include Mongoid::Slug | ||
| field :title | ||
| field :content | ||
|
|
||
| field :page_category | ||
| field :page_sub_category | ||
|
|
||
| field :order, type: Integer | ||
| slug :title, scope: %i[page_category page_sub_category] | ||
| default_scope -> { asc(:order) } | ||
| end |
Uh oh!
There was an error while loading. Please reload this page.