avo-hq / avo

Build Ruby on Rails apps 10x faster
https://avohq.io
Other
1.44k stars 228 forks source link

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

Open cyu opened 2 months ago

cyu commented 2 months ago

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:

Are you using Avo monkey patches, overriding views or view components?

Screenshots or screen recordings

Additional context

Impact

Urgency

adrianthedev commented 2 months ago

Thanks @cyu! @gabrielgiroe1 will investigate this shortly.

adrianthedev commented 2 months ago

Related to https://github.com/avo-hq/avo/issues/2651

cyu commented 2 months ago

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 commented 2 months ago

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

cyu commented 1 month ago

@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 commented 1 month ago

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.

https://github.com/avo-hq/avo/assets/1334409/3dc3cefd-0025-48f7-ba53-5ac7e80e284b

cyu commented 1 month ago

@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 commented 1 month ago

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

cyu commented 1 month ago

@adrianthedev https://github.com/cyu/avo-test

gabrielgiroe1 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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

cyu commented 1 month ago

@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 commented 1 month ago

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

github-actions[bot] commented 1 month ago

This issue has been marked as stale because there was no activity for the past 15 days.