Opinions on pushing the id field into the payload config/collections object/array returned by getPayload #6836
mcornielje090404
started this conversation in
Feature Requests & Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I'm wanting to make a contribution to the payload repo where we push the id field on collections into the "collections" array available on the payload object.
My reasoning for this change is that I noticed passing an "id" into the create function for a record doesn't set the id that's pushed into the db to that value. This can be a real pain for seeding as relations are not maintained across multiple seeds which can have massive implications when trying to pull down the current content on an app and reseed it.
E.g. you have a "pages" table that has blocks which have fields that relate to another table in the DB. Ideally I could pull down all the data available for a page including the blocks and relations then put them back into the DB with all the relations maintained (and potentially tweak them within my seed files). I could come up with a fancy way to somehow maintain these relations within the seed files but that's a large chunk of work and seems unnecessary when I could just keep the id's as is in the DB and have no issues.
Doing a code deep dive I noticed that when you transform the objects for writing to the DB you cycle through the fields currently in the payload "fields" array on a collection and rebuild the object to write using that.
Are there any implications with something like this?
I have already written a potential way to do this here though admittedly I'm not 100% sure if it's the correct way. If all looks good I'll raise a PR for it.
NOTE: I'm working on the payload 3.0 beta currently.
Beta Was this translation helpful? Give feedback.
All reactions