def conditions_to_fields(conditions)
      fields = {}
      conditions.each do |key, value|
        if value.is_a?(::ActiveRecord::Base) && (assoc = klass.reflect_on_association(key.to_sym)) && assoc.belongs_to?

          if ::ActiveRecord::VERSION::STRING < "3.1"
            fields[assoc.primary_key_name] = value.send(value.class.primary_key)
            fields[assoc.options[:foreign_type]] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
          else # >= 3.1
            fields[assoc.foreign_key] = value.send(value.class.primary_key)
            fields[assoc.foreign_type] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
          end

        else
          fields[key] = value
        end
      end
      fields
    end
def conditions_to_fields(conditions)
      fields = {}
      conditions.each do |key, value|
        if value.is_a?(::ActiveRecord::Base) && (assoc = klass.reflect_on_association(key.to_sym)) && assoc.belongs_to?

          if ::ActiveRecord::VERSION::STRING < "3.1"
            fields[assoc.primary_key_name] = value.send(value.class.primary_key)
            fields[assoc.options[:foreign_type]] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
          else # >= 3.1
            fields[assoc.foreign_key] = value.send(value.class.primary_key)
            fields[assoc.foreign_type] = value.class.base_class.name.to_s if assoc.options[:polymorphic]
          end

        else
          fields[key] = value
        end
      end
      fields
    end
Introspects the klass to convert and objects in conditions into foreign key and type fields