Commit cced76cf by Jon Yurek

Updated the rake task to take STI into consideration.

parent 5ec90a56
...@@ -14,10 +14,26 @@ def obtain_attachments ...@@ -14,10 +14,26 @@ def obtain_attachments
end end
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 def for_all_attachments
klass = obtain_class klass = obtain_class
names = obtain_attachments names = obtain_attachments
ids = klass.connection.select_values("SELECT #{klass.primary_key} FROM #{klass.table_name}") ids = klass.connection.select_values("SELECT #{quote_column(klass.primary_key)} FROM #{quote_table(klass.table_name)} #{type_condition(klass)}")
ids.each do |id| ids.each do |id|
instance = klass.find(id) instance = klass.find(id)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment