diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-02 20:49:19 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-03-05 09:52:58 +0900 |
commit | 4331478996d6086bb089c1e33956a1c0fa9000b1 (patch) | |
tree | df43ca3a6da0aee240f5c7cf87bcbf35168e1268 /activerecord/lib/active_record/persistence.rb | |
parent | e117d9266e577675afe1462e37601c029e21091b (diff) | |
download | rails-4331478996d6086bb089c1e33956a1c0fa9000b1.tar.gz rails-4331478996d6086bb089c1e33956a1c0fa9000b1.tar.bz2 rails-4331478996d6086bb089c1e33956a1c0fa9000b1.zip |
Refactor `_substitute_values` to be passed attribute names and values
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index 8f9cb85a90..28308da96d 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -169,12 +169,11 @@ module ActiveRecord primary_key_value = nil if primary_key && Hash === values - arel_primary_key = arel_attribute(primary_key) - primary_key_value = values[arel_primary_key] + primary_key_value = values[primary_key] if !primary_key_value && prefetch_primary_key? primary_key_value = next_sequence_value - values[arel_primary_key] = primary_key_value + values[primary_key] = primary_key_value end end @@ -208,8 +207,9 @@ module ActiveRecord end def _substitute_values(values) - values.map do |attr, value| - bind = predicate_builder.build_bind_attribute(attr.name, value) + values.map do |name, value| + attr = arel_attribute(name) + bind = predicate_builder.build_bind_attribute(name, value) [attr, bind] end end @@ -705,7 +705,7 @@ module ActiveRecord # Returns the number of affected rows. def _update_record(attribute_names = self.attribute_names) attribute_names &= self.class.column_names - attributes_values = arel_attributes_with_values_for_update(attribute_names) + attributes_values = attributes_with_values_for_update(attribute_names) if attributes_values.empty? rows_affected = 0 @_trigger_update_callback = true @@ -723,7 +723,7 @@ module ActiveRecord # and returns its id. def _create_record(attribute_names = self.attribute_names) attribute_names &= self.class.column_names - attributes_values = arel_attributes_with_values_for_create(attribute_names) + attributes_values = attributes_with_values_for_create(attribute_names) new_id = self.class._insert_record(attributes_values) self.id ||= new_id if self.class.primary_key |