Skip to content

Commit

Permalink
Support composite primary keys on show, edit, update and destroy acti…
Browse files Browse the repository at this point in the history
…ons (#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](rails/rails@da7a6da).

Co-authored-by: Paul Bob <[email protected]>

---------

Co-authored-by: Paul Bob <[email protected]>
  • Loading branch information
filipegiusti and Paul-Bob authored Apr 9, 2024
1 parent 530c942 commit 52bec77
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/avo/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 157 in app/controllers/avo/application_controller.rb

View check run for this annotation

UndercoverCI / coverage

Untested instance method

Instance method `set_record` is missing coverage for lines 149..150 (node coverage: 0.6667). Missing branch coverage found in line 149.
Raw output
148:     def set_record hits: n/a
149:       id = if @resource.model_class.primary_key.is_a?(Array) && params.respond_to?(:extract_value) hits: 635 branches: 0/1
150:         params.extract_value(:id) hits: 0
151:       else hits: n/a
152:         params[:id] hits: 635
153:       end hits: n/a
154: 
155:       @record = @resource.find_record(id, query: model_scope, params:) hits: 635
156:       @resource.hydrate(record: @record) hits: 635
157:     end hits: n/a

Expand Down

0 comments on commit 52bec77

Please sign in to comment.