Module: MongoMapper::Plugins::CounterCache

Extended by:
ActiveSupport::Concern
Included in:
Document
Defined in:
lib/mongo_mapper/plugins/counter_cache.rb

Overview

Counter Caching for MongoMapper::Document

Examples:

class Post
  belongs_to :user
  counter_cache :user
end

or:

class Post
  belongs_to :user
  counter_cache :user, :custom_posts_count
end

Field names follow rails conventions, so counter_cache :user will increment the Integer field ‘posts_count’ on User

Alternatively, you can also use the more common ActiveRecord syntax:

class Post
  belongs_to :user, :counter_cache => true
end

Or with an alternative field name:

class Post
  belongs_to :user, :counter_cache => :custom_posts_count
end

Defined Under Namespace

Modules: ClassMethods Classes: InvalidCounterCacheError