Description
Describe the bug
I'd like to use a polymorphic belongs to field in an action. I would expect if I do that, the action handle
method will receive a type and an id value for that field. However, it only receives a type value (no id) and that produces an error.
Steps to Reproduce
Steps to reproduce the behavior:
- Create a new action
- Add a fields block with a polymorphic belongs to, for example:
def fields
field :reviewable, as: :belongs_to, polymorphic_as: :reviewable, types: [::Post, ::Team]
end
and a handle block that looks like this:
def handle(fields:)
warn fields.inspect
end
- Try using the action and select something from the polymorphic belongs to
Expected behavior & Actual behavior
It should show a warning similar to: '{"reviewable_type": "Post", "reviewable_id": 12345}' but instead it will show just '{"reviewable_type": "Post"}' (with no id field).
Models and resource files
In the example above I've assumed the resources in the avo demo app
System configuration
Avo version: 3.10.9
Rails version: 7.0.8.4
Ruby version: 3.3.2
License type:
- Community
- Pro
- Advanced
Are you using Avo monkey patches, overriding views or view components?
- Yes. If so, please post code samples.
- No
Screenshots or screen recordings
Additional context
I've looked at the code and the issue seems to be with Avo::BaseAction#handle_action
in this bit of code:
action_fields = get_field_definitions.map do |field|
field.hydrate(resource: @resource)
[field.id, field]
end.to_h
At this point, the get_field_definitions
returns the field for the polymorphic belongs to and I can see that the fields passed to the action has values for both the type and id inputs, but after this block of code there is only a value for the type (and the id is lost).
I have a workaround for now, which is I've added an extra hidden field to the action for the id of the polymorphic belongs to. If I do that then both values are returned from this block.
Impact
- High impact (It makes my app un-usable.)
- Medium impact (I'm annoyed, but I'll live.)
- Low impact (It's really a tiny thing that I could live with.)
Urgency
- High urgency (I can't continue development without it.)
- Medium urgency (I found a workaround, but I'd love to have it fixed.)
- Low urgency (It can wait. I just wanted you to know about it.)
Metadata
Metadata
Assignees
Labels
Type
Projects
Status