Closed RasmusGodske closed 6 months ago
Thank you for the extensive bug report, I was able to replicate it in a test and fix the issue.
The mediaCollections was a regular indexed array. I now made it a key, value array with the name being the key. This should ensure that even when the register method is called no duplicates will be added.
The fix should be in the next release of the package.
Issue Overview: When using methods like
getMediaCollection
orgetRegisteredMediaCollections
from theInteractsWithMedia
trait,registerMediaCollections
is invoked multiple times. This behavior leads to multiple identical entries being added to the mediaCollections array, potentially causing unexpected behavior when interacting with media collections.Steps to Reproduce:
Define a MediaCollection in a model using the registerMediaCollections method:
Call getRegisteredMediaCollections() multiple times on the same model instance:
Observe that the documents collection is registered multiple times in the mediaCollections array.
Expected Behavior: registerMediaCollections should ensure that it only adds unique media collections, or it should only be called once per instance to prevent duplicate registrations.
Actual Behavior: Every call to getRegisteredMediaCollections() or similar methods results in repeated registration of the same media collections.
Proposed Solutions:
Own temporary solution:
I got around the issue with this quick and dirty solution: