Skip to content

Commit

Permalink
Check for counter cache property on parent_model
Browse files Browse the repository at this point in the history
  • Loading branch information
Saimon Moore committed Dec 21, 2008
1 parent 8e357cf commit 8787a72
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/dm-counter-cache.rb
Expand Up @@ -37,14 +37,14 @@ def setup_with_counter_caching(name, model, options = {})
after :destroy, :decrement_counter_cache_for_#{name}
def increment_counter_cache_for_#{name}
return unless self.#{name}.class.properties.has_property?(:#{counter_cache_attribute})
return unless ::#{relationship.parent_model}.properties.has_property?(:#{counter_cache_attribute})
if self.#{name} && self.class == #{model.name}
self.#{name}.update_attributes(:#{counter_cache_attribute} => self.#{name}.reload.#{counter_cache_attribute}.succ)
end
end
def decrement_counter_cache_for_#{name}
return unless self.#{name}.class.properties.has_property?(:#{counter_cache_attribute})
return unless ::#{relationship.parent_model}.properties.has_property?(:#{counter_cache_attribute})
if self.#{name} && self.class == #{model.name}
self.#{name}.update_attributes(:#{counter_cache_attribute} => self.#{name}.reload.#{counter_cache_attribute} - 1)
end
Expand Down

0 comments on commit 8787a72

Please sign in to comment.