Module: FriendlyId::History::SlugGenerator

Defined in:
lib/friendly_id/history.rb

Overview

This module overrides SlugGenerator#conflicts to consider all historic slugs for that model.

Instance Method Summary collapse

Instance Method Details

#conflictsObject (private)



122
123
124
125
126
127
128
129
130
131
# File 'lib/friendly_id/history.rb', line 122

def conflicts
  sluggable_class = friendly_id_config.model_class.base_class
  pkey            = sluggable_class.primary_key
  value           = sluggable.send pkey

  scope = Slug.with_deleted.where("slug = ? OR slug LIKE ?", normalized, wildcard)
  scope = scope.where(:sluggable_type => sluggable_class.to_s)
  scope = scope.where("sluggable_id <> ?", value) unless sluggable.new_record?
  scope.order("LENGTH(slug) DESC, slug DESC")
end