Sha256: 86f8e9f3b31a80ecc46b13e8ac1fe761529d29c5a545a73a80a00e902ecfe91b
Contents?: true
Size: 742 Bytes
Versions: 40
Compression:
Stored size: 742 Bytes
Contents
# frozen_string_literal: true class UpdateRootCommentableForComments < ActiveRecord::Migration[5.0] def up # rubocop:disable Rails/SkipsModelValidations Decidim::Comments::Comment.where(depth: 0).update_all( "decidim_root_commentable_id = decidim_commentable_id, decidim_root_commentable_type = decidim_commentable_type" ) # rubocop:enable Rails/SkipsModelValidations Decidim::Comments::Comment.where("depth > 0").find_each do |comment| comment.root_commentable = root_commentable(comment) comment.save(validate: false) end end def down; end private def root_commentable(comment) return comment.commentable if comment.depth.zero? root_commentable comment.commentable end end
Version data entries
40 entries across 40 versions & 1 rubygems