Sha256: 7e1c6eaa29549de72cefc07c8ebba0fcc820f4f12d3233cf18073db2ecb7c39c
Contents?: true
Size: 918 Bytes
Versions: 14
Compression:
Stored size: 918 Bytes
Contents
# frozen_string_literal: true class AddCommentVoteCounterCacheToComments < ActiveRecord::Migration[6.1] def change add_column :decidim_comments_comments, :up_votes_count, :integer, null: false, default: 0, index: true add_column :decidim_comments_comments, :down_votes_count, :integer, null: false, default: 0, index: true # We cannot use the reset_counters as up_votes and down_votes are scoped associationws reversible do |dir| dir.up do Decidim::Comments::Comment.reset_column_information Decidim::Comments::Comment.find_each do |record| # rubocop:disable Rails/SkipsModelValidations record.class.update_counters(record.id, up_votes_count: record.up_votes.length) record.class.update_counters(record.id, down_votes_count: record.down_votes.length) # rubocop:enable Rails/SkipsModelValidations end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems