Commit 65649aa4 by Bartosz Bonisławski

Monkeypatch activerecord relations to work with rails >=5.2.0rc2

parent a3286408
......@@ -14,7 +14,7 @@ env:
- RAILS='~> 4.2.0'
- RAILS='~> 5.0.0'
- RAILS='~> 5.1.0'
- RAILS='~> 5.2.0.beta2'
- RAILS='~> 5.2.0.rc2'
matrix:
allow_failures:
......@@ -24,5 +24,5 @@ matrix:
rvm: jruby-9.1.6.0
- env: RAILS='~> 5.1.0'
rvm: jruby-9.1.6.0
- env: RAILS='~> 5.2.0.beta2'
- env: RAILS='~> 5.2.0.rc2'
rvm: jruby-9.1.6.0
require 'active_record' unless defined? ActiveRecord
require 'paranoia/active_record_patches'
module Paranoia
@@default_sentinel_value = nil
......
module HandleParanoiaDestroyedInBelongsToAssociation
def handle_dependency
return unless load_target
case options[:dependent]
when :destroy
target.destroy
if defined? target.deleted?
raise ActiveRecord::Rollback unless target.deleted?
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 defined? target.deleted?
throw(:abort) unless target.deleted?
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment