Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Counter Cache when using STI throws: You have a nil object when you didn't expect it! #18
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
patroza
Dec 20, 2011
I have worked around the issue by specifying the is_impressionable :counter_cache => .... in each STI model subclass.
Preferably this would not be needed :)
patroza
commented
Dec 20, 2011
I have worked around the issue by specifying the is_impressionable :counter_cache => .... in each STI model subclass. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
coryschires
Dec 20, 2011
Contributor
I agree, you should not need to re-specify in the subclasses. I'll have a look at it over the next few days to see if we can make this smarter.
I agree, you should not need to re-specify in the subclasses. I'll have a look at it over the next few days to see if we can make this smarter. |
ghost
assigned
coryschires
May 8, 2013
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment Hide comment
Has this issue been fixed? can we close it? |
patroza commentedDec 20, 2011
The model uses Single Table Inheritance. If the type column is blank, the issue does not occur.
In model:
is_impressionable :counter_cache => { :column_name => :view_counter_cache }
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.[]
Backtrace:
impressionist (1.0.1) app/models/impressionist/impressionable.rb:47:in
update_counter_cache' activesupport (3.1.3) lib/active_support/core_ext/object/try.rb:32:in
try'impressionist (1.0.1) app/models/impression.rb:13:in
update_impressions_counter_cache' activesupport (3.1.3) lib/active_support/callbacks.rb:401:in
_run_save_callbacks'activesupport (3.1.3) lib/active_support/callbacks.rb:81:in
run_callbacks' activerecord (3.1.3) lib/active_record/callbacks.rb:264:in
create_or_update'activerecord (3.1.3) lib/active_record/persistence.rb:37:in
save' activerecord (3.1.3) lib/active_record/validations.rb:50:in
save'activerecord (3.1.3) lib/active_record/attribute_methods/dirty.rb:22:in `save'
The problem seems to stem from using self.class.counter_cache_options