Skip to content

Commit

Permalink
Added competability with HABTM
Browse files Browse the repository at this point in the history
  • Loading branch information
tinchi committed Sep 5, 2014
1 parent a07216c commit 60ccb55
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/mongoid/magic_counter_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ def counter_cache(*args, &block)
end
else
relation = doc.send(name)
if relation && relation.class.fields.keys.include?(counter_name)
increment_association(relation, counter_name.to_sym, inc)
relation = [relation] unless relation.respond_to?(:each)
relation.each do |entry|
if entry && entry.class.fields.keys.include?(counter_name)
increment_association(entry, counter_name.to_sym, inc)
end
end
end
end
Expand Down

0 comments on commit 60ccb55

Please sign in to comment.