Sha256: fdcbbab07865d46a0e2afee1b95debb0eb1d877dce2781bcc9fd81af1a2d5ebc
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
# frozen_string_literal: true # Support destroy for rails belongs_to assocations. module HandlePermanentRecordsDestroyedInBelongsToAssociation def handle_dependency return unless load_target # only patch :destroy case and delegate to super otherwise case options[:dependent] when :destroy target.destroy raise ActiveRecord::Rollback if target.respond_to?(:deleted?) && !target.deleted? else super end end end # Support destroy for rails has_one associations. module HandlePermanentRecordsDestroyedInHasOneAssociation def delete(method = options[:dependent]) return unless load_target # only patch :destroy case and delegate to super otherwise case method when :destroy target.destroyed_by_association = reflection target.destroy throw(:abort) if target.respond_to?(:deleted?) && !target.deleted? else super(method) end end end ActiveRecord::Associations::BelongsToAssociation.prepend(HandlePermanentRecordsDestroyedInBelongsToAssociation) ActiveRecord::Associations::HasOneAssociation.prepend(HandlePermanentRecordsDestroyedInHasOneAssociation)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
permanent_records-6.0.1 | lib/permanent_records/active_record.rb |