Modifying field breaks update?

default discord avatar
mvarendorff
3 months ago
2

I am currently trying to move an existing upload field to a custom group field that connects to an external service for file-hosting. This however seems to break our seeding script when existing data is present (which is kinda bad if some data is already present in a staging environment that you want to update).



The field previously was


{name: 'media', type: 'upload', relationTo: 'media', required: true}

and now is


{name: 'media', type: 'group', interfaceName: 'MyCustomMedia', fields: [/* a lot of stuff */]}


Our seeder attempts to update existing values using


await payload.update({id, data: {/* here be data including a media object */}});

However in an

afterRead

hook on one of the new fields, it turns out the value of the media field is still a string instead of an object.



What am I missing here to fix my update?



Actually... Ignore this for a minute, we might be doing something stupid 🤔



The

afterRead

hook is also called

before

updating which blew up our new field's resolvers. Handling that specific case fixes the seeder!

    Open the post
    Continue the discussion in Discord
    Like what we're doing?
    Star us on GitHub!

    Star

    Connect with the Payload Community on Discord

    Discord

    online

    Can't find what you're looking for?

    Get help straight from the Payload team with an Enterprise License.