mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fixed that clear_association_cache doesn't delete new associations on new records (so you can safely place new records in the session with Action Pack without having new associations wiped) #1494 [cluon]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1504 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fixed that clear_association_cache doesn't delete new associations on new records (so you can safely place new records in the session with Action Pack without having new associations wiped) #1494 [cluon]
|
||||
|
||||
* Fixed that calling Model.find([]) returns [] and doesn't throw an exception #1379
|
||||
|
||||
* Fixed that adding a record to a has_and_belongs_to collection would always save it -- now it only saves if its a new record #1203 [Alisdair McDiarmid]
|
||||
|
||||
@@ -17,7 +17,7 @@ module ActiveRecord
|
||||
def clear_association_cache #:nodoc:
|
||||
self.class.reflect_on_all_associations.to_a.each do |assoc|
|
||||
instance_variable_set "@#{assoc.name}", nil
|
||||
end
|
||||
end unless self.new_record?
|
||||
end
|
||||
|
||||
# Associations are a set of macro-like class methods for tying objects together through foreign keys. They express relationships like
|
||||
|
||||
@@ -826,4 +826,25 @@ class BasicsTest < Test::Unit::TestCase
|
||||
assert_equal res, res2
|
||||
end
|
||||
|
||||
def test_clear_association_cache_stored
|
||||
firm = Firm.find(1)
|
||||
assert_kind_of Firm, firm
|
||||
|
||||
firm.clear_association_cache
|
||||
assert_equal Firm.find(1).clients.collect{ |x| x.name }.sort, firm.clients.collect{ |x| x.name }.sort
|
||||
end
|
||||
|
||||
def test_clear_association_cache_new_record
|
||||
firm = Firm.new
|
||||
client_stored = Client.find(3)
|
||||
client_new = Client.new
|
||||
client_new.name = "The Joneses"
|
||||
clients = [ client_stored, client_new ]
|
||||
|
||||
firm.clients << clients
|
||||
|
||||
firm.clear_association_cache
|
||||
|
||||
assert_equal firm.clients.collect{ |x| x.name }.sort, clients.collect{ |x| x.name }.sort
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user