Skip to content

Commit

Permalink
Explicitly use base class when looking up slugs
Browse files Browse the repository at this point in the history
Previously model_class was not being properly set on STI classes; now
that it is, we need to take this consideration
  • Loading branch information
norman committed Mar 13, 2012
1 parent f3892e6 commit 3846ae7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/friendly_id/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def exists?(id = false)
# Accepts a slug, and yields a corresponding sluggable_id into the block.
def with_old_friendly_id(slug, &block)
sql = "SELECT sluggable_id FROM #{Slug.quoted_table_name} WHERE sluggable_type = %s AND slug = %s"
sql = sql % [@klass.base_class.name, slug].map {|x| connection.quote(x)}
sql = sql % [@klass.base_class.to_s, slug].map {|x| connection.quote(x)}
sluggable_id = connection.select_values(sql).first
yield sluggable_id if sluggable_id
end
Expand All @@ -120,12 +120,12 @@ module SlugGenerator
private

def conflicts
sluggable_class = friendly_id_config.model_class
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.name)
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
Expand Down

0 comments on commit 3846ae7

Please sign in to comment.