From 52bec77b0d8e13ef3616f868a5b9d02722e9d28e Mon Sep 17 00:00:00 2001 From: Filipe Giusti Date: Tue, 9 Apr 2024 11:48:28 -0300 Subject: [PATCH] Support composite primary keys on show, edit, update and destroy actions (#2645) * Support composite primary keys on show, edit, update and destroy actions Impressively, this seems to be all that's required to support composite primary keys. * Do not break for Rails < 7.1 when adding support to composite primary keys `params.extract_values` was [introduced in Rails 7.1.0.beta1](https://github.com/rails/rails/commit/da7a6da4e7f5caf227420c550a8a13550dd9c682). Co-authored-by: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> --------- Co-authored-by: Paul Bob <69730720+Paul-Bob@users.noreply.github.com> --- app/controllers/avo/application_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/avo/application_controller.rb b/app/controllers/avo/application_controller.rb index f549f5766a..6cc79d5c5d 100644 --- a/app/controllers/avo/application_controller.rb +++ b/app/controllers/avo/application_controller.rb @@ -146,7 +146,13 @@ def set_related_resource end def set_record - @record = @resource.find_record(params[:id], query: model_scope, params: params) + id = if @resource.model_class.primary_key.is_a?(Array) && params.respond_to?(:extract_value) + params.extract_value(:id) + else + params[:id] + end + + @record = @resource.find_record(id, query: model_scope, params:) @resource.hydrate(record: @record) end