Skip to content

Commit

Permalink
Add note about indexes to README
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyshields authored Sep 17, 2023
1 parent b46fddd commit 6b6ad2f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ post = Post.find 'a-thousand-plateaus' # Finds by slugs
post = Post.find '50b1386a0482939864000001' # Finds by bson ids
=> ...
```

[Examine slug.rb](lib/mongoid/slug.rb) for all available options.

### Updating Existing Records
Expand Down Expand Up @@ -133,6 +134,23 @@ The `to_url` method comes from [stringex](https://github.com/rsl/stringex).

You can define a slug builder globally and/or override it per model.

### Indexing

By default, Mongoid Slug will automatically generate an index for the slug, which will be created when you run `rake db:create_indexes`. This index will take into account scoping and other options described below.

To skip this index generation, you may set `index: false` as follows:

```ruby
class Employee
include Mongoid::Document
include Mongoid::Slug

field :name

slug :name, index: :false
end
```

### Scoping

To scope a slug by a reference association, pass `:scope`:
Expand Down

0 comments on commit 6b6ad2f

Please sign in to comment.