saimonmoore / dm-counter-cache

DataMapper::CounterCacheable allows you to transparently maintain counts on a collection association for a DataMapper::Resource object.

This URL has Read+Write access

name age message
file History.txt Sun Dec 14 03:48:16 -0800 2008 Initial commit [Saimon Moore]
file LICENSE Sun Dec 14 03:48:16 -0800 2008 Initial commit [Saimon Moore]
file Manifest.txt Sun Dec 14 03:48:16 -0800 2008 Initial commit [Saimon Moore]
file README.txt Sun Dec 14 03:48:16 -0800 2008 Initial commit [Saimon Moore]
file Rakefile Sun Dec 14 04:43:24 -0800 2008 Adding hoe dep [Saimon Moore]
file TODO Sun Dec 14 03:48:16 -0800 2008 Initial commit [Saimon Moore]
directory lib/ Sun Dec 21 09:19:36 -0800 2008 Ensuring callbacks are only defined once [Saimon Moore]
directory spec/ Sun Dec 21 08:42:10 -0800 2008 Updating specs to manually specify counter cach... [Saimon Moore]
directory tasks/ Sun Dec 14 04:43:24 -0800 2008 Adding hoe dep [Saimon Moore]
README.txt
== README

DataMapper::CounterCacheable automates the dec/incrementing of association counter fields. This is
similar to counter caches in ActiveRecord.

Example:

class Post
  include DataMapper::Resource

  has n :comments

  property :id, Integer, :serial => true
  property :comments_count, Integer, :default => 0
end

class Comment
  include DataMapper::Resource
  include DataMapper::CounterCacheable  

  belongs_to :post, :counter_cache => true

end