Class: ForestLiana::HasManyAssociator

Inherits:
Object
  • Object
show all
Includes:
RecordFindable
Defined in:
app/services/forest_liana/has_many_associator.rb

Instance Method Summary collapse

Constructor Details

#initialize(resource, association, params) ⇒ HasManyAssociator

Returns a new instance of HasManyAssociator.



5
6
7
8
9
10
# File 'app/services/forest_liana/has_many_associator.rb', line 5

def initialize(resource, association, params)
  @resource = resource
  @association = association
  @params = params
  @data = params['data']
end

Instance Method Details

#performObject



12
13
14
15
16
17
18
19
20
21
# File 'app/services/forest_liana/has_many_associator.rb', line 12

def perform
  @record = find_record(@resource, @resource, @params[:id])
  associated_records = @record.send(@association.name)

  if @data.is_a?(Array)
    @data.each do |record_added|
      associated_records << @association.klass.find(record_added[:id])
    end
  end
end