aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorMarcin Raczkowski <marcin.raczkowski@gmail.com>2010-08-28 20:56:02 +0200
committerEmilio Tagua <miloops@gmail.com>2010-11-19 19:04:39 -0300
commitc357f842e2131443033207d6f3a5f957cd6ab450 (patch)
tree50f27fe07799e2ad7fcf297c182508769908fbc2 /activerecord/lib/active_record/persistence.rb
parentce66bfdc54e3c1a4a726ebbdd3207f327d4297cf (diff)
downloadrails-c357f842e2131443033207d6f3a5f957cd6ab450.tar.gz
rails-c357f842e2131443033207d6f3a5f957cd6ab450.tar.bz2
rails-c357f842e2131443033207d6f3a5f957cd6ab450.zip
IdentityMap - adding and removing of records on create/update
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb14
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 594a2214bb..a7181fd79b 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -64,7 +64,10 @@ module ActiveRecord
# callbacks, Observer methods, or any <tt>:dependent</tt> association
# options, use <tt>#destroy</tt>.
def delete
- self.class.delete(id) if persisted?
+ if persisted?
+ self.class.delete(id)
+ IdentityMap.remove(self)
+ end
@destroyed = true
freeze
end
@@ -73,6 +76,7 @@ module ActiveRecord
# that no changes should be made (since they can't be persisted).
def destroy
if persisted?
+ IdentityMap.remove(self)
self.class.unscoped.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all
end
@@ -196,7 +200,12 @@ module ActiveRecord
def reload(options = nil)
clear_aggregation_cache
clear_association_cache
- @attributes.update(self.class.unscoped { self.class.find(self.id, options) }.instance_variable_get('@attributes'))
+
+ IdentityMap.without do
+ fresh_object = self.class.unscoped { self.class.find(self.id, options) }
+ @attributes.update(fresh_object.instance_variable_get('@attributes'))
+ end
+
@attributes_cache = {}
self
end
@@ -270,6 +279,7 @@ module ActiveRecord
self.id ||= new_id
+ IdentityMap.add(self)
@persisted = true
id
end