# WITHOUT cached_models class Author < ActiveRecord::Base has_many :posts has_many :comments, :through => :posts def full_name @full_name ||= [ first_name, last_name ].join(" ") end end class Post < ActiveRecord::Base belongs_to :author has_many :comments has_many :tags, :as => :taggable end class Comment < ActiveRecord::Base belongs_to :post end class Tag < ActiveRecord::Base belongs_to :taggable, :polymorphic => true end # WITH cached_models class CachedAuthor < ActiveRecord::Base has_many :cached_posts, :cached => true has_many :cached_comments, :through => :cached_posts, :cached => true def full_name @full_name ||= [ first_name, last_name ].join(" ") end end class CachedPost < ActiveRecord::Base belongs_to :cached_author, :cached => true has_many :cached_comments, :cached => true has_many :cached_tags, :as => :taggable, :cached => true end class CachedComment < ActiveRecord::Base belongs_to :cached_post, :cached => true end class CachedTag < ActiveRecord::Base belongs_to :taggable, :polymorphic => true, :cached => true end