laravel / nova-issues

554 stars 34 forks source link

BelongsTo fails validation when creating if already exists on another record #6409

Closed grantholle closed 5 months ago

grantholle commented 5 months ago

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.
crynobone commented 5 months ago

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)

grantholle commented 5 months ago

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

grantholle commented 5 months ago

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