Skip to content

Commit

Permalink
fix(association): return bad request if associated record is not dest…
Browse files Browse the repository at this point in the history
…roy on 8.x.x (#689)
  • Loading branch information
nicolasalexandre9 authored Sep 18, 2024
1 parent 227a9f6 commit d3d31e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/forest_liana/associations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def dissociate
dissociator.perform

head :no_content
rescue ActiveRecord::RecordNotDestroyed => error
render json: { errors: [{ status: :bad_request, detail: error.message }] }, status: :bad_request
rescue => error
FOREST_REPORTER.report error
FOREST_LOGGER.error "Association Dissociate error: #{error}\n#{format_stacktrace(error)}"
Expand Down
7 changes: 6 additions & 1 deletion app/services/forest_liana/has_many_dissociator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ def perform

if @with_deletion
record_ids = record_ids.select { |record_id| @association.klass.exists?(record_id) }
@association.klass.destroy(record_ids)
@resource.transaction do
record_ids.each do |id|
record = @association.klass.find(id)
record.destroy!
end
end
end
end
end
Expand Down

0 comments on commit d3d31e2

Please sign in to comment.