def resolve_model_reflections
      # TODO: cach the result using and instance_var or something
      reflections = model.reflections
      columns     = Set.new model.column_names
      new_fields  = Set.new
      fields_to_remove = Set.new

      reflections.each do |name, column|
        has_many = ActiveRecord::Reflection::HasManyReflection
        has_and_belongs_to_many = ActiveRecord::Reflection::HasAndBelongsToManyReflection

        if !column.is_a?(has_many) && !column.is_a?(has_and_belongs_to_many)
          new_fields << name.to_s
          fields_to_remove << column.foreign_key.to_s
        end
      end

      if model.respond_to? :attachment_definitions
        # Paperclip is installed and model contains attachments
        model.attachment_definitions.each do |name, _|
          new_fields << name.to_s
          ["file_name", "content_type", "file_size", "updated_at"].each do |x|
            fields_to_remove << "#{name}_#{x}"
          end
        end
      end

      columns.union(new_fields) - fields_to_remove
    end
def resolve_model_reflections
      # TODO: cach the result using and instance_var or something
      reflections = model.reflections
      columns     = Set.new model.column_names
      new_fields  = Set.new
      fields_to_remove = Set.new

      reflections.each do |name, column|
        has_many = ActiveRecord::Reflection::HasManyReflection
        has_and_belongs_to_many = ActiveRecord::Reflection::HasAndBelongsToManyReflection

        if !column.is_a?(has_many) && !column.is_a?(has_and_belongs_to_many)
          new_fields << name.to_s
          fields_to_remove << column.foreign_key.to_s
        end
      end

      if model.respond_to? :attachment_definitions
        # Paperclip is installed and model contains attachments
        model.attachment_definitions.each do |name, _|
          new_fields << name.to_s
          ["file_name", "content_type", "file_size", "updated_at"].each do |x|
            fields_to_remove << "#{name}_#{x}"
          end
        end
      end

      columns.union(new_fields) - fields_to_remove
    end
Replace foreign key names with their reflection names
 and create an array of model fields