0
cached_association_proxy
0
).each { |file| require File.join("acts_as_cached", "cached_associations", file)}
0
@@ -17,9 +18,9 @@ module ActsAsCached
0
- # class User < ActiveRecord::Base
0
- # has_many_cached :cats
0
+ # class User < ActiveRecord::Base
0
+ # has_many_cached :cats
0
def has_many_cached(association_id, options = {}, &extensions)
0
raise "Cannot have :limit and :order on has_many_cached associations" if options[:order] || options[:limit]
0
@@ -28,17 +29,35 @@ module ActsAsCached
0
- # class User < ActiveRecord::Base
0
+ # class User < ActiveRecord::Base
0
- # class Cat < ActiveRecord::Base
0
- # belongs_to_cached :user
0
+ # class Cat < ActiveRecord::Base
0
+ # belongs_to_cached :user
0
def belongs_to_cached(association_id, options = {}, &extensions)
0
belongs_to(association_id, options, &extensions)
0
create_belongs_to_cached_reflection(association_id, options)
0
+ # A macro to define a has_many relationship and the accompanying cache machinery specifically to
0
+ # handle an association that is paginated and displayed in reverse chronological order (implemented
0
+ # by ordering using "id DESC").
0
+ # class User < ActiveRecord::Base
0
+ # # Blog posts are displayed automagically ordered by "id DESC", 10 at a time.
0
+ # has_paginated_list :blog_posts, :limit => 10
0
+ def has_paginated_list(association_id, options = {})
0
+ raise ":limit and :order are required options for a has_paginated_list association." unless options[:limit]
0
+ association_class = options[:class_name] ? options[:class_name].to_s.constantize : association_id.to_s.classify.constantize
0
+ has_many(association_id, options.merge({:order => "#{association_class.primary_key} DESC"}))
0
+ create_has_paginated_list_reflection(association_id, options)
0
read_inheritable_attribute(:cached_reflections) || write_inheritable_attribute(:cached_reflections, {})
0
@@ -56,6 +75,12 @@ module ActsAsCached
0
write_inheritable_hash :cached_reflections, name => reflection
0
+ def create_has_paginated_list_reflection(name, options)
0
+ reflection = ActsAsCached::CachedAssociations::HasPaginatedListReflection.new(:has_paginated_list, name, options, self)
0
+ write_inheritable_hash :cached_reflections, name => reflection
Comments
No one has commented yet.