-
-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix belongs_to
and ID field linking to child resources if configured
#3109
Fix belongs_to
and ID field linking to child resources if configured
#3109
Conversation
Code Climate has analyzed commit 93c1117 and detected 0 issues on this pull request. View more on Code Climate. |
@Paul-Bob @adrianthedev , if there is anything I can do to help you guys with reviewing this PR, do let me know |
I'm reviewing it, thank you @stevegeek |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment to cover the for_attribute
scenario, otherwise, it's looking great @stevegeek! Thank you!
app/components/avo/base_component.rb
Outdated
|
||
@resource.link_to_child_resource | ||
end | ||
|
||
def field_linked_to_child_resource? | ||
field.present? && field.respond_to?(:link_to_child_resource) && field.link_to_child_resource | ||
resolved_field = @reflection ? @parent_resource.get_field(@reflection.name) : field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this will not find the field when using for_attribute
option. For example:
field :the_children, as: :has_many, for_attribute: :children, link_to_child_resource: true
This should cover that scenario, can you please verify that?
resolved_field = @reflection ? @parent_resource.get_field(@reflection.name) : field | |
resolved_field = @reflection ? @parent_resource.get_field(params[:for_attribute] || @reflection.name) : field |
@@ -19,6 +27,36 @@ | |||
end | |||
end | |||
|
|||
context "Resource show page links to associated resources" do | |||
let(:paul) { create :sibling, name: "paul" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great name! :D
Thanks @stevegeek. |
Description
If a resource includes a
belongs_to
field which relates to a record which uses STI, then the current behaviour is that the link rendered on theshow
page for the resource to the associated record always links to the parent class resource. In other places this behaviour is controlled bylink_to_child_resource
but not here.Related, if
id_links_to_resource
is used andlink_to_child_resource
is set for an association, the link does not respect thelink_to_child_resource
setting.This PR updates the
belongs_to
field to respect thelink_to_child_resource
option, which can either be set on the Resource, or set on the field.It also changes the way BaseComponent determines if a field should
link_to_child_resource
by using the association reflection and checking the related association.I believe this fixes #2629 and fixes #2782
Checklist:
Screenshots & recording
I have checked this in an application using Avo but can't share screenshots from it.
Manual review steps
Manual reviewer: please leave a comment with output from the test if that's the case.