diff options
author | thedarkone <thedarkone2@gmail.com> | 2013-09-11 14:18:31 +0200 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2013-09-11 14:18:31 +0200 |
commit | 5cbed2bc606750c71ee231d2b816471fe241459e (patch) | |
tree | dac1c587f0cf6f6388ad91a83fa689e7e5d6b71a /activerecord/lib | |
parent | 05f88b7b0499781f87e9e79cbec4d01193db2352 (diff) | |
download | rails-5cbed2bc606750c71ee231d2b816471fe241459e.tar.gz rails-5cbed2bc606750c71ee231d2b816471fe241459e.tar.bz2 rails-5cbed2bc606750c71ee231d2b816471fe241459e.zip |
Relation#merge should not lose readonly(false) flag.
The original code ignores the `false` value because `false.blank? # => true`.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/relation/merger.rb | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/relation/merger.rb b/activerecord/lib/active_record/relation/merger.rb index 530c47d0d0..c05632e688 100644 --- a/activerecord/lib/active_record/relation/merger.rb +++ b/activerecord/lib/active_record/relation/merger.rb @@ -58,7 +58,11 @@ module ActiveRecord def merge normal_values.each do |name| value = values[name] - relation.send("#{name}!", *value) unless value.blank? + # The unless clause is here mostly for performance reasons (since the `send` call might be moderately + # expensive), most of the time the value is going to be `nil` or `.blank?`, the only catch is that + # `false.blank?` returns `true`, so there needs to be an extra check so that explicit `false` values + # don't fall through the cracks. + relation.send("#{name}!", *value) unless value.nil? || (value.blank? && false != value) end merge_multi_values |