awcodes / filament-curator

A media picker plugin for Filament Panels.
MIT License
343 stars 89 forks source link

Fix issue - media type always gets updated on saving MorphMany relationship #527

Closed m7moudabdel7mid closed 3 months ago

m7moudabdel7mid commented 3 months ago

Hi,

This pull request addresses a bug with saving a MorphMany relationship where records are not properly filtered by their type before being updated. This causes the type column of some records to be incorrectly overwritten, leading to data inconsistencies and duplicate records.

Steps to Reproduce:

  1. Create two CuratorPicker components with different typeValue attributes for the same relationship:

    CuratorPicker::make('media_1')->multiple()->typeValue('t1')->relationship('media_items', 'id'),
    CuratorPicker::make('media_2')->multiple()->typeValue('t2')->relationship('media_items', 'id'),
  2. Select the same file in both pickers and save. The first save works correctly.

  3. Save again, and observe that all media_items are incorrectly updated to type 't1', with a new record created for type 't2'.

This fix ensures that records are filtered by typeValue before updates, preventing incorrect modifications and maintaining data integrity.

awcodes commented 3 months ago

Thanks. 😀