Skip to content

Instantly share code, notes, and snippets.

@tcocca
Created May 3, 2010 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tcocca/388463 to your computer and use it in GitHub Desktop.
Save tcocca/388463 to your computer and use it in GitHub Desktop.
class Post < ActiveRecord::Base
has_many :authors
attr_accessor :post_authors_cache
def post_authors
process_post_authors if post_authors_cache.nil?
post_authors_cache
end
private
def process_post_authors
#do some crazy stuff here and set the post_authors_cache
self.post_authors_cache = {} #some crazy hash of stuff based on some inane business logic
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment