diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-06 14:18:01 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-06 14:24:16 -0600 |
commit | 36e9be8524ff524ac5ea51dd1fc6ee33cfe4285a (patch) | |
tree | 975bdf30a004091e7d0a25cfd9fce25e3c807c26 | |
parent | 6680ee9427ae2639e404cd3b9538f54e136057c6 (diff) | |
download | rails-36e9be8524ff524ac5ea51dd1fc6ee33cfe4285a.tar.gz rails-36e9be8524ff524ac5ea51dd1fc6ee33cfe4285a.tar.bz2 rails-36e9be8524ff524ac5ea51dd1fc6ee33cfe4285a.zip |
Remove composed_of special case from multi-parameter attributes
As we move towards removing the `klass` method from `column`, the else
clause as it stands right now will become the only case.
-rw-r--r-- | activerecord/lib/active_record/aggregations.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_assignment.rb | 7 |
2 files changed, 7 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index 45c275a017..4fead8d251 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -244,6 +244,10 @@ module ActiveRecord def writer_method(name, class_name, mapping, allow_nil, converter) define_method("#{name}=") do |part| klass = class_name.constantize + if part.is_a?(Hash) + part = klass.new(*part.values) + end + unless part.is_a?(klass) || converter.nil? || part.nil? part = converter.respond_to?(:call) ? converter.call(part) : klass.send(converter, part) end diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index c4cf084a04..40e2918777 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -126,8 +126,8 @@ module ActiveRecord def read_value return if values.values.compact.empty? - @column = object.class.reflect_on_aggregation(name.to_sym) || object.column_for_attribute(name) - klass = column.klass + @column = object.column_for_attribute(name) + klass = column ? column.klass : nil if klass == Time read_time @@ -186,8 +186,7 @@ module ActiveRecord positions = (1..max_position) validate_required_parameters!(positions) - set_values = values.values_at(*positions) - klass.new(*set_values) + values.slice(*positions) end # Checks whether some blank date parameter exists. Note that this is different |