lib/whyvalidationssuckin96/rails/macros/validates_uniqueness.rb in whyvalidationssuckin96-1.3.0 vs lib/whyvalidationssuckin96/rails/macros/validates_uniqueness.rb in whyvalidationssuckin96-1.3.1
- old
+ new
@@ -59,13 +59,18 @@
end
def scope_columns
Array(options[:scope])
end
-
+
def find_conditions
- ["LOWER(#{scope_class.connection.quote_column_name(attribute.to_s)}) = LOWER(?)", attribute_value]
+ column = scope_class.columns.detect { |col| col.name == attribute.to_s }
+ if column.type == :text or column.type == :string
+ ["LOWER(#{scope_class.connection.quote_column_name(attribute.to_s)}) = LOWER(?)", attribute_value]
+ else
+ ["#{scope_class.connection.quote_column_name(attribute.to_s)} = ?", attribute_value]
+ end
end
def scope_conditions
scope_columns.inject({}) do |conds,col|
conds[col] = validatable[col]
@@ -82,6 +87,6 @@
end
end # Validation
ValidationBuilder.register_macro :validates_uniqueness_of, WhyValidationsSuckIn96::ValidatesUniqueness
-end # WhyValidationsSuckIn96
\ No newline at end of file
+end # WhyValidationsSuckIn96