Skip to content
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

ID field within has_many field does not link to child resource #2782

Open
4 of 11 tasks
cyu opened this issue May 18, 2024 · 14 comments
Open
4 of 11 tasks

ID field within has_many field does not link to child resource #2782

cyu opened this issue May 18, 2024 · 14 comments
Assignees

Comments

@cyu
Copy link

cyu commented May 18, 2024

Describe the bug

The ID field within a has_many field always links to the base class resource even when link_to_child_resource is true.

Steps to Reproduce

Steps to reproduce the behavior:

Consider having the setup in the STI example here: https://docs.avohq.io/2.0/associations.html#link-to-child-resource-when-using-sti

  1. In the avo.rb initializer, enable id_links_to_resource: config.id_links_to_resource = true
  2. Go to the Show page of the resource that has the peoples field
  3. Click on the linked ID column of one of the peoples row
  4. You will be take to the resource Show page of the base class (PersonResource)

Expected behavior & Actual behavior

When you click on the linked ID column, the expectation is that it will take you to the show page of the child resource (SpouseResource or SiblingResource). Instead it takes you to the base class resource (PersonResoure). If you use the View icon button, it will actually take you to the correct child record.

System configuration

Avo version: 3.3.2

Rails version: 7.1 3

Ruby version: 3.2.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

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.)
@adrianthedev
Copy link
Collaborator

Thanks @cyu!
@gabrielgiroe1 will investigate this shortly.

@adrianthedev
Copy link
Collaborator

Related to #2651

@cyu
Copy link
Author

cyu commented May 18, 2024

I did look into this a bit, and the issue seems to be how IndexComponent checks field_linked_to_child_resource? on the ID field when it should be checking on the has_many field.

@adrianthedev
Copy link
Collaborator

Ok. That might be the fix!
Would you be open to try and send in a fix?

@cyu
Copy link
Author

cyu commented May 21, 2024

@adrianthedev I can give it a shot, but I need some guidance on how to navigate to the parent has_many field in that scenario.

@adrianthedev
Copy link
Collaborator

adrianthedev commented May 21, 2024

Hey @cyu can you please confirm if it works or not on the demo website?
https://avodemo.com/avo/resources/people

I think I see it working.

CleanShot.2024-05-21.at.22.36.58.mp4

@cyu
Copy link
Author

cyu commented May 27, 2024

@adrianthedev It works from the People index view; where it doesn't work is from a child view.

For example, if you add to Person has_many :parents, class_name: "Person", and then add a has_many field for family on the Person resource.

@adrianthedev
Copy link
Collaborator

Can you please create a reproduction repo so we can test it out?

@cyu
Copy link
Author

cyu commented May 28, 2024

@gabrielgiroe1
Copy link
Collaborator

The issue arises when you create a Person without specifying a type and then attach a child to this Person. When you click on theID of the Person, you expect to be redirected to the child, but this does not happen because the Person does not have a type defined.

@gabrielgiroe1
Copy link
Collaborator

Hi, @cyu! I did some more digging and managed to reproduce the bug you were describing. that bug is fixed in Avo 3. Avo 2 is not receiving any more bug fixes, but only security fixes.

@gabrielgiroe1
Copy link
Collaborator

I will close this to keep the issue queue clean. Let me know if there's anything else I can help with.

@cyu
Copy link
Author

cyu commented May 29, 2024

@gabrielgiroe1 What version of Avo 3 is this in? My repro example was done in Avo 3.7.4

Please re-review this issue and the example repro project. I don't believe this is solved. It doesn't make sense that the ID link had the view link would behave differently in this case.

@gabrielgiroe1 gabrielgiroe1 reopened this May 29, 2024
@gabrielgiroe1
Copy link
Collaborator

I misunderstood that it would be on Avo 2. We will look to check if it is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

3 participants