Class: ForestLiana::HasManyDissociator
- Inherits:
-
Object
- Object
- ForestLiana::HasManyDissociator
- Defined in:
- app/services/forest_liana/has_many_dissociator.rb
Instance Method Summary collapse
-
#initialize(resource, association, params) ⇒ HasManyDissociator
constructor
A new instance of HasManyDissociator.
- #perform ⇒ Object
Constructor Details
#initialize(resource, association, params) ⇒ HasManyDissociator
Returns a new instance of HasManyDissociator.
3 4 5 6 7 8 |
# File 'app/services/forest_liana/has_many_dissociator.rb', line 3 def initialize(resource, association, params) @resource = resource @association = association @params = params @data = params['data'] end |
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/services/forest_liana/has_many_dissociator.rb', line 10 def perform @record = @resource.find(@params[:id]) associated_records = @resource.find(@params[:id]).send(@association.name) if @data.is_a?(Array) @data.each do |record_deleted| associated_records.delete( @association.klass.find(record_deleted[:id])) end end end |