Changeset 4721
- Timestamp:
- 08/08/06 16:59:06 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/associations.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/associations/association_proxy.rb (modified) (2 diffs)
- trunk/activerecord/test/associations_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4706 r4721 1 1 *SVN* 2 3 * Cache nil results for has_one associations so multiple calls don't call the database. Closes #5757. [Michael A. Schoen] 2 4 3 5 * Add documentation for how to disable timestamps on a per model basis. Closes #5684. [matt@mattmargolis.net Marcel Molina Jr.] trunk/activerecord/lib/active_record/associations.rb
r4690 r4721 657 657 before_save <<-EOF 658 658 association = instance_variable_get("@#{reflection.name}") 659 if !association.nil?659 if association && association.target 660 660 if association.new_record? 661 661 association.save(true) … … 842 842 association = association_proxy_class.new(self, reflection) 843 843 retval = association.reload 844 unless retval.nil? 845 instance_variable_set("@#{reflection.name}", association) 846 else 844 if retval.nil? and association_proxy_class == BelongsToAssociation 847 845 instance_variable_set("@#{reflection.name}", nil) 848 846 return nil 849 847 end 850 end 851 association 848 instance_variable_set("@#{reflection.name}", association) 849 end 850 851 association.target.nil? ? nil : association 852 852 end 853 853 trunk/activerecord/lib/active_record/associations/association_proxy.rb
r4398 r4721 127 127 if !@owner.new_record? || foreign_key_present 128 128 begin 129 @target = find_target if !loaded?129 @target = find_target unless loaded? 130 130 rescue ActiveRecord::RecordNotFound 131 131 reset … … 133 133 end 134 134 135 loaded if target135 loaded 136 136 target 137 137 end trunk/activerecord/test/associations_test.rb
r4690 r4721 95 95 assert_equal companies(:first_firm).account, Account.find(1) 96 96 assert_equal Account.find(1).credit_limit, companies(:first_firm).account.credit_limit 97 end 98 99 def test_has_one_cache_nils 100 assert_nil companies(:another_firm).account 101 assert_queries(0) { companies(:another_firm).account } 97 102 end 98 103