laravel/nova-issues

Autofill on HasMany relationship doesn't work when defined twice.

YouneselBarnoussi opened this issue · 3 comments

  • Laravel Version: 11.7.0
  • Nova Version: 4.33.0
  • PHP Version: 8.2.18
  • Database Driver & Version: Mysql 8.0
  • Operating System and Version: Ubuntu 22.04.4 LTS
  • Browser type and version: Google Chrome Versie 122.0.6261.112
  • Reproduction Repository: https://github.com/YouneselBarnoussi/nova-hasmany-bug

Description:

The BelongsTo field doesn't always fill when there are two HasMany relationships to the same model. When you go to the detail page of the model and click on 'Create Relation' the BelongsTo field does get filled for the related model in the first relationship but not in the second. For more clarification check below.

Detailed steps to reproduce the issue on a fresh Nova installation:

A complete guide is found in the readme of the reproduction repository but I will copy it here aswell:

Lets say we have a user that can belong to many teams. The TeamUser pivot/model has a role which is used to filter between admins and members.

The Team model has two HasMany relationships to TeamUser admins() and members(), the difference is the filteration on the role column.

Now navigate to the teams resource and go to the detail page of the team.

Click on Create Team User for admins. You can see that the Team relationship is automatically filled with the correct team.

Now go back.

Click on Create Team User for members. You can see that the Team relationship is empty for some reason.

Now go to the file Team Nova resource file and move the members relationship above the admin relationship, and repeat the steps above.

Then you will see the same result but flipped, so it seems like the autofill only works for the first relationship.

Can you send a video example of the step above?

2024-05-20.16-12-55.mp4

Let me know if there is anything else I can help with

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.