diff --git a/lib/has_permalink.rb b/lib/has_permalink.rb index 6c9d9a3..4ae26f6 100644 --- a/lib/has_permalink.rb +++ b/lib/has_permalink.rb @@ -53,7 +53,11 @@ def to_param # Autofix duplication of permalinks def fix_duplication(permalink) if auto_fix_duplication - n = self.class.where(["permalink = ?", permalink]).count + n = if id.present? + self.class.where(["permalink = ? AND id != ?", permalink, id]).count + else + self.class.where(["permalink = ?", permalink]).count + end if n > 0 links = self.class.where(["permalink LIKE ?", "#{permalink}%"]).order("id")