Skip to content

Commit

Permalink
Changed the STI query to use #construct_finder_sql as per Joe Van Dyk…
Browse files Browse the repository at this point in the history
…'s suggestion.
  • Loading branch information
Jon Yurek committed Jan 13, 2009
1 parent cced76c commit 75d10b9
Showing 1 changed file with 1 addition and 17 deletions.
18 changes: 1 addition & 17 deletions tasks/paperclip_tasks.rake
Expand Up @@ -14,26 +14,10 @@ def obtain_attachments
end
end

def quote_table(table)
ActiveRecord::Base.connection.quote_table_name(table)
end

def quote_column(column)
ActiveRecord::Base.connection.quote_column_name(column)
end

def type_condition(klass)
if klass.superclass == ActiveRecord::Base
""
else
"WHERE #{quote_column(klass.inheritance_column)} = '#{klass.name}'"
end
end

def for_all_attachments
klass = obtain_class
names = obtain_attachments
ids = klass.connection.select_values("SELECT #{quote_column(klass.primary_key)} FROM #{quote_table(klass.table_name)} #{type_condition(klass)}")
ids = klass.connection.select_values(klass.send(:construct_finder_sql, :select => 'id'))

ids.each do |id|
instance = klass.find(id)
Expand Down

0 comments on commit 75d10b9

Please sign in to comment.