public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Search Repo:
 r3387@asus:  jeremy | 2005-12-07 20:48:42 -0800
 Apply [3242] to stable.  Reloading an instance refreshes its aggregations 
 as well as its associations.  Closes #3024.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3243 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jeremy (author)
Wed Dec 07 20:48:50 -0800 2005
commit  bd9b27df8b372c6cc3eb2978e4ef95f68226cdfb
tree    ed9fd03599b2e498bdb5848aaa5ab94317ea575a
parent  c6120acc006ec7b6a2bc9353fb384169cb162388
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 * SVN*
0
 
0
+* Reloading an instance refreshes its aggregations as well as its associations. #3024 [François Beausolei]
0
+
0
 * Fixed that using :include together with :conditions array in Base.find would cause NoMethodError #2887 [Paul Hammmond]
0
 
0
 * PostgreSQL: more robust sequence name discovery. #3087 [Rick Olson]
...
5
6
7
 
 
 
 
 
 
8
9
10
...
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -5,6 +5,12 @@
0
       base.extend(ClassMethods)
0
     end
0
 
0
+ def clear_aggregation_cache #:nodoc:
0
+ self.class.reflect_on_all_aggregations.to_a.each do |assoc|
0
+ instance_variable_set "@#{assoc.name}", nil
0
+ end unless self.new_record?
0
+ end
0
+
0
     # Active Record implements aggregation through a macro-like class method called +composed_of+ for representing attributes
0
     # as value objects. It expresses relationships like "Account [is] composed of Money [among other things]" or "Person [is]
0
     # composed of [an] address". Each call to the macro adds a description of how the value objects are created from the
...
1304
1305
1306
 
1307
1308
1309
...
1304
1305
1306
1307
1308
1309
1310
0
@@ -1304,6 +1304,7 @@
0
 
0
       # Reloads the attributes of this object from the database.
0
       def reload
0
+ clear_aggregation_cache
0
         clear_association_cache
0
         @attributes.update(self.class.find(self.id).instance_variable_get('@attributes'))
0
         self
...
44
45
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
...
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
0
@@ -44,5 +44,24 @@
0
     assert_equal "39", customers(:david).gps_location.latitude
0
     assert_equal "-110", customers(:david).gps_location.longitude
0
   end
0
+
0
+ def test_reloaded_instance_refreshes_aggregations
0
+ assert_equal "35.544623640962634", customers(:david).gps_location.latitude
0
+ assert_equal "-105.9309951055148", customers(:david).gps_location.longitude
0
+
0
+ Customer.update_all("gps_location = '24x113'")
0
+ customers(:david).reload
0
+ assert_equal '24x113', customers(:david)['gps_location']
0
+
0
+ assert_equal GpsLocation.new('24x113'), customers(:david).gps_location
0
+ end
0
+
0
+ def test_gps_equality
0
+ assert GpsLocation.new('39x110') == GpsLocation.new('39x110')
0
+ end
0
+
0
+ def test_gps_inequality
0
+ assert GpsLocation.new('39x110') != GpsLocation.new('39x111')
0
+ end
0
 end
...
44
45
46
 
 
 
 
47
...
44
45
46
47
48
49
50
51
0
@@ -44,5 +44,9 @@
0
   def longitude
0
     gps_location.split("x").last
0
   end
0
+
0
+ def ==(other)
0
+ self.latitude == other.latitude && self.longitude == other.longitude
0
+ end
0
 end

Comments

    No one has commented yet.