Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Counter Cache column options do not accept multiple columns #19

Closed
sickboy opened this Issue · 2 comments

2 participants

@sickboy

I would like to cache both, total views and unique views.

The following does not make that happen (for obvious reasons):
is_impressionable :counter_cache => { :column_name => :view_counter_cache }
is_impressionable :counter_cache => { :column_name => :view_counter_cache_unique, :unique => true }

Is there a way to achieve this regardless, or could it be added?

Example:
is_impressionable :counter_cache => [{:column_name => :counter_cache}, {:column_name => :counter_cache_unique, :unique => true}]

or:

is_impressionable :counter_cache => {:counter_cache => {}, :counter_cache_unique => {:unique => true}}

@johnmcaliley

This would definitely be useful. The first example seems a little cleaner. I could also see this accommodating other conditions other than "unique" by accepting a lambda (like rails before_filter does). We should keep the original syntax, but allow the user to pass an array as well. I think we will have to change counter_cache_options and update_counter_cache in this module:

https://github.com/charlotte-ruby/impressionist/blob/master/app/models/impressionist/impressionable.rb

You can take a stab at it if you want. I will merge the changes if you do a pull request and include tests. coryschires may be able to help if you have any questions. He added the counter cache code to impressionist

@sickboy

Thanks! I will give it a shot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.