Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Added comments and add explicit ordering to this method, which makes …

…the result deterministic and resumeable should an error occur mid-way.
  • Loading branch information...
commit 0df5a960fbf463b169c4e085c529f1062b19c1f1 1 parent 7243015
@tilsammans tilsammans authored jyurek committed
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/paperclip.rb
4 lib/paperclip.rb
@@ -138,8 +138,10 @@ def register_processor(name, processor)
@known_processors[name.to_s] = processor
+ # Find all instances of the given Active Record model +klass+ with attachment +name+.
+ # This method is used by the refresh rake tasks.
def each_instance_with_attachment(klass, name)
- class_for(klass).all.each do |instance|
+ class_for(klass).find(:all, :order => 'id').each do |instance|
yield(instance) if instance.send(:"#{name}?")

1 comment on commit 0df5a96


When working with a legacy database imported from a legacy project which does not have an "id" column (but another column as primary key), "rake paperclip:refresh" no longer works because it tries to sort the table by id instead of by the primary key defined by the model.

I cannot rename the column because the legacy application still needs to access rows by its naming scheme ("imageid" is the primary key).

Although this change seems to make sense it destroys compatibility with Rails' support for legacy databases. The primary key should be extracted from the model and not put here statically, or there should be an option to set this key name.

Please sign in to comment.
Something went wrong with that request. Please try again.