-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multi-level counter-cache doesn't work with Discard #342
Comments
For now we mitigated the issue with custom scope: class Step < ActiveRecord::Base
include Discard::Model
belongs_to :lesson, class_name: 'Lesson'
scope :within_kept, -> { kept.where(lesson_id: Lesson.kept.select(:id)) }
counter_culture %i[lesson unit], column_name: ->(_) { 'steps_count' },
column_names: {
Step.within_kept => :steps_count
}
counter_culture :lesson
end |
This sounds right—do you think you can put a pull request together to fix this? I don't use discard so wouldn't get around to fixing this myself. |
Was this ever merged? Or do I use the above solution? |
Nobody ever put together a PR to fix this, so there was nothing to merge. I don't have the time to work on this myself. If you can put together a PR for this I'd be happy to merge it! |
It seems that couter_culture checks Discard of only one level of models hierarchy, but not all of them.
For example:
Expected:
Step.counter_culture_fix_counts
also takes into account discarded_at of parent model.Actual:
Step.counter_culture_fix_counts
checks only discarded_at of Step, but any model on hierarchy.The text was updated successfully, but these errors were encountered: