Skip to content

Commit 861d76f

Browse files
fix(relation): fix dissociate all records of relationship (#618)
1 parent 709c41f commit 861d76f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

app/controllers/forest_liana/associations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def associate
7272

7373
def dissociate
7474
begin
75-
dissociator = HasManyDissociator.new(@resource, @association, params)
75+
dissociator = HasManyDissociator.new(@resource, @association, params, forest_user)
7676
dissociator.perform
7777

7878
head :no_content

app/services/forest_liana/has_many_dissociator.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
module ForestLiana
2-
class HasManyDissociator < ForestLiana::ApplicationController
3-
def initialize(resource, association, params)
2+
class HasManyDissociator
3+
def initialize(resource, association, params, forest_user)
44
@resource = resource
55
@association = association
66
@params = params
77
@with_deletion = @params[:delete].to_s == 'true'
88
@data = params['data']
9+
@forest_user = forest_user
910
end
1011

1112
def perform
1213
@record = @resource.find(@params[:id])
1314
associated_records = @resource.find(@params[:id]).send(@association.name)
1415

1516
remove_association = !@with_deletion || @association.macro == :has_and_belongs_to_many
16-
1717
if @data.is_a?(Array)
1818
record_ids = @data.map { |record| record[:id] }
1919
elsif @data.dig('attributes').present?
20-
record_ids = ForestLiana::ResourcesGetter.get_ids_from_request(@params, forest_user)
20+
record_ids = ForestLiana::ResourcesGetter.get_ids_from_request(@params, @forest_user)
2121
else
2222
record_ids = Array.new
2323
end

0 commit comments

Comments
 (0)