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

- (Object) conflicts (private)



122
123
124
125
126
127
128
129
130
131
132
133
134
# 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.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?

  length_command = "LENGTH"
  length_command = "LEN" if sluggable.connection.adapter_name =~ /sqlserver/i
  scope.order("#{length_command}(slug) DESC, slug DESC")
end