diff --git a/lib/validates_timeliness/active_record/multiparameter_attributes.rb b/lib/validates_timeliness/active_record/multiparameter_attributes.rb index 68de263..a2d4fa6 100644 --- a/lib/validates_timeliness/active_record/multiparameter_attributes.rb +++ b/lib/validates_timeliness/active_record/multiparameter_attributes.rb @@ -16,18 +16,16 @@ module ValidatesTimeliness def execute_callstack_for_multiparameter_attributes_with_timeliness(callstack) errors = [] callstack.each do |name, values| - klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass - if values.empty? - send(name + "=", nil) - else - column = column_for_attribute(name) + column = column_for_attribute(name) + if column && [:date, :time, :datetime].include?(column.type) begin - value = if [:date, :time, :datetime].include?(column.type) - time_array_to_string(values, column.type) + callstack.delete(name) + if values.empty? + send("#{name}=", nil) else - klass.new(*values) + value = time_array_to_string(values, column.type) + send("#{name}=", value) end - send(name + "=", value) rescue => ex errors << ::ActiveRecord::AttributeAssignmentError.new("error on assignment #{values.inspect} to #{name}", ex, name) end @@ -36,10 +34,11 @@ module ValidatesTimeliness unless errors.empty? raise ::ActiveRecord::MultiparameterAssignmentErrors.new(errors), "#{errors.size} error(s) on assignment of multiparameter attributes" end + execute_callstack_for_multiparameter_attributes_without_timeliness(callstack) end def time_array_to_string(values, type) - values = values.map(&:to_s) + values = values.map {|v| v.to_s } case type when :date