aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-09 19:20:48 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-09 19:21:33 -0300
commit6e5ab6fccb55727ef2e32c30a77a48c595316cae (patch)
tree3f95cd0bd4186b1e5ab34158cd41c67bb379df99 /activerecord/lib
parentf56cdbdfb2cb0f9f989b377b21d6d30d3d4f7d03 (diff)
downloadrails-6e5ab6fccb55727ef2e32c30a77a48c595316cae.tar.gz
rails-6e5ab6fccb55727ef2e32c30a77a48c595316cae.tar.bz2
rails-6e5ab6fccb55727ef2e32c30a77a48c595316cae.zip
Change uniq validation with conditions examples to use where with hashes
Take the opportunity to showcase where.not.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/validations/uniqueness.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/validations/uniqueness.rb b/activerecord/lib/active_record/validations/uniqueness.rb
index bf2aa2e959..a705d8c2c4 100644
--- a/activerecord/lib/active_record/validations/uniqueness.rb
+++ b/activerecord/lib/active_record/validations/uniqueness.rb
@@ -4,7 +4,7 @@ module ActiveRecord
def initialize(options)
if options[:conditions] && !options[:conditions].respond_to?(:call)
raise ArgumentError, "#{options[:conditions]} was passed as :conditions but is not callable. " \
- "Pass a callable instead: `conditions: -> { where('approved = ?', true) }`"
+ "Pass a callable instead: `conditions: -> { where(approved: true) }`"
end
super({ case_sensitive: true }.merge!(options))
end
@@ -120,7 +120,7 @@ module ActiveRecord
# of the title attribute:
#
# class Article < ActiveRecord::Base
- # validates_uniqueness_of :title, conditions: -> { where('status != ?', 'archived') }
+ # validates_uniqueness_of :title, conditions: -> { where.not(status: 'archived') }
# end
#
# When the record is created, a check is performed to make sure that no
@@ -136,7 +136,7 @@ module ActiveRecord
# the uniqueness constraint.
# * <tt>:conditions</tt> - Specify the conditions to be included as a
# <tt>WHERE</tt> SQL fragment to limit the uniqueness constraint lookup
- # (e.g. <tt>conditions: -> { where('status = ?', 'active') }</tt>).
+ # (e.g. <tt>conditions: -> { where(status: 'active') }</tt>).
# * <tt>:case_sensitive</tt> - Looks for an exact match. Ignored by
# non-text columns (+true+ by default).
# * <tt>:allow_nil</tt> - If set to +true+, skips this validation if the