Sha256: ebaa8ee23ca990719855dc8177eb441ee1102e46b90d2cb68748818b95aacb3f
Contents?: true
Size: 1.2 KB
Versions: 14
Compression:
Stored size: 1.2 KB
Contents
module HandleParanoiaDestroyedInBelongsToAssociation def handle_dependency return unless load_target case options[:dependent] when :destroy target.destroy if target.respond_to?(:paranoia_destroyed?) raise ActiveRecord::Rollback unless target.paranoia_destroyed? else raise ActiveRecord::Rollback unless target.destroyed? end else target.send(options[:dependent]) end end end module HandleParanoiaDestroyedInHasOneAssociation def delete(method = options[:dependent]) if load_target case method when :delete target.delete when :destroy target.destroyed_by_association = reflection target.destroy if target.respond_to?(:paranoia_destroyed?) throw(:abort) unless target.paranoia_destroyed? else throw(:abort) unless target.destroyed? end when :nullify target.update_columns(reflection.foreign_key => nil) if target.persisted? end end end end ActiveRecord::Associations::BelongsToAssociation.prepend HandleParanoiaDestroyedInBelongsToAssociation ActiveRecord::Associations::HasOneAssociation.prepend HandleParanoiaDestroyedInHasOneAssociation
Version data entries
14 entries across 14 versions & 1 rubygems