Skip to content

Commit

Permalink
Merge pull request #330 from btrepp/master
Browse files Browse the repository at this point in the history
Fix LENGTH undefined in microsoft sqlserver
  • Loading branch information
parndt committed Dec 6, 2012
2 parents b07a13c + 707096d commit 5b8be2c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/friendly_id/slug_generator.rb
Expand Up @@ -59,7 +59,10 @@ def conflicts
base << "ESCAPE '\\'" if sluggable.connection.adapter_name =~ /sqlite/i
scope = sluggable_class.unscoped.where(base, normalized, wildcard)
scope = scope.where("#{pkey} <> ?", value) unless sluggable.new_record?
scope = scope.order("LENGTH(#{column}) DESC, #{column} DESC")

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

def friendly_id_config
Expand Down

0 comments on commit 5b8be2c

Please sign in to comment.