Skip to content
This repository
Browse code

Fixed that that multiparameter assignment doesn't work with aggregati…

…ons (closes #4620) [Lars Pind]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4188 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8eb73f43e1f7eb6f7afa7838e64b259c81bc8a47 1 parent 6400367
David Heinemeier Hansson authored April 06, 2006
4  activerecord/CHANGELOG
... ...
@@ -1,6 +1,8 @@
  1
+*1.14.1* (April 6th, 2005)
  2
+
1 3
 * Fix type_name_with_module to handle type names that begin with '::'. Closes #4614. [Nicholas Seckar]
2 4
 
3  
-*1.14.1* (April 6th, 2005)
  5
+* Fixed that that multiparameter assignment doesn't work with aggregations (closes #4620) [Lars Pind]
4 6
 
5 7
 * Enable Limit/Offset in Calculations (closes #4558) [lmarlow@yahoo.com]
6 8
 
2  activerecord/lib/active_record/base.rb
@@ -1988,7 +1988,7 @@ def assign_multiparameter_attributes(pairs)
1988 1988
       def execute_callstack_for_multiparameter_attributes(callstack)
1989 1989
         errors = []
1990 1990
         callstack.each do |name, values|
1991  
-          klass = (self.class.reflect_on_aggregation(name) || column_for_attribute(name)).klass
  1991
+          klass = (self.class.reflect_on_aggregation(name.to_sym) || column_for_attribute(name)).klass
1992 1992
           if values.empty?
1993 1993
             send(name + "=", nil)
1994 1994
           else
9  activerecord/test/base_test.rb
@@ -2,6 +2,7 @@
2 2
 require 'fixtures/topic'
3 3
 require 'fixtures/reply'
4 4
 require 'fixtures/company'
  5
+require 'fixtures/customer'
5 6
 require 'fixtures/developer'
6 7
 require 'fixtures/project'
7 8
 require 'fixtures/default'
@@ -721,6 +722,14 @@ def test_multiparameter_mass_assignment_protector
721 722
     task.attributes = attributes
722 723
     assert_equal time, task.starting
723 724
   end
  725
+  
  726
+  def test_multiparameter_assignment_of_aggregation
  727
+    customer = Customer.new
  728
+    address = Address.new("The Street", "The City", "The Country")
  729
+    attributes = { "address(1)" => address.street, "address(2)" => address.city, "address(3)" => address.country }
  730
+    customer.attributes = attributes
  731
+    assert_equal address, customer.address
  732
+  end
724 733
 
725 734
   def test_attributes_on_dummy_time
726 735
     # Oracle and SQL Server do not have a TIME datatype.
4  activerecord/test/fixtures/customer.rb
@@ -14,6 +14,10 @@ def initialize(street, city, country)
14 14
   def close_to?(other_address)
15 15
     city == other_address.city && country == other_address.country
16 16
   end
  17
+
  18
+  def ==(other)
  19
+    other.is_a?(self.class) && other.street == street && other.city == city && other.country == country
  20
+  end  
17 21
 end
18 22
 
19 23
 class Money

0 notes on commit 8eb73f4

Please sign in to comment.
Something went wrong with that request. Please try again.