Open vbiletskii opened 2 months ago
Interesting edge case.
Can you please try to update the attach_scope
on the Comment
resource?
field :commentable,
as: :belongs_to,
polymorphic_as: :commentable,
disabled: true,
types: [User, Admin],
default: -> { record },
attach_scope: -> { query.include(:personal_information) }
The code above is untested. It might need tweaking.
Interesting edge case. Can you please try to update the
attach_scope
on theComment
resource?field :commentable, as: :belongs_to, polymorphic_as: :commentable, disabled: true, types: [User, Admin], default: -> { record }, attach_scope: -> { query.include(:personal_information) } The code above is untested. It might need tweaking.
Thanks for the help, @adrianthedev! It helps somewhat, but it still loads all associations from types
when I just want to create a comment for one of them. Additionally, if there's another model like Booking
(without an association like has_many :personal_information
), it will throw an error.
Got it @vbiletskii. Please create a minimal reproduction repo with all the models and resources that we can troubleshoot and we'll gladly apply a solution.
Please use this guide on how to create one.
https://docs.avohq.io/3.0/technical-support.html#reproduction-repository
@adrianthedev Here's the repository: https://github.com/vbiletskii/polymorphic-issue. Let me know if you need anything else from me - really appreciate all your help!
Describe the bug
I have polymorphic associations in place, and when I try to create a
Comment
in theUser
view, I encounter an n+1 issue even though I have included the dependent association.Steps to Reproduce
Steps to reproduce the behavior:
https://github.com/vbiletskii/polymorphic_issue
to reproduce the issueExpected behavior & Actual behavior
Expected behavior: It loads only one record with its title (name) to display in the field. Actual behavior: It loads all records from
types: [User, Admin]
with their titles, causing an n+1 issue.Models and resource files
System configuration
Avo version:
3.10.1
Rails version:7.1.3
Ruby version:3.2.2
License type:Are you using Avo monkey patches, overriding views or view components?
Screenshots or screen recordings
https://github.com/user-attachments/assets/011718b1-bbdd-4e52-a95a-8ea71784711d
Additional context
Impact
Urgency