laravel/nova-issues

BelongsTo fails validation when creating if already exists on another record

grantholle opened this issue · 3 comments

  • Laravel Version: 11.8.0
  • Nova Version: 4.34.2
  • PHP Version: 8.3.3
  • Database Driver & Version: Postgres 14
  • Operating System and Version: macOS 14.5
  • Browser type and version: Brave v1.66.113

Description:

When attempting to create a resource with a BelongsTo relation value that already is associated with another resource, it will fail validation with the message "This {field resource name} may not be associated with this resource."

I can, however, save the BelongsTo as null and update it with the same resource value that was used when trying to create it.

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

  1. Create a BelongsTo relationship and field on a model.
  2. Create a new resource in Nova with a value for the BelongsTo field.
  3. Attempt to create another resource with the same BelongsTo field value.
  4. See validation message.
  5. Save as an empty/null value.
  6. Update the resource with the original BelongsTo value.
  7. Updates successfully.

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

I tried but can't reproduce it. That's a great feeling.

I found it had to do with my reciprocal relationship. Just needed to be refactored.