Save relation items order (Issue #2166)

I also ran into this for one of our clients. We managed to play around with the lifecycles and perform a raw query like this in the beforeUpdate:

await strapi.connections.default.raw(`DELETE FROM ${model}s__blocks WHERE ${model}_id = ${data.id};`);

Our relation here was “blocks”. Basically, what we are doing is clearing all the rows before save and re-save them after the post is saved. It’s not pretty, but it served it’s purpose. Please be careful though as if the beforeUpdate has ran, but something went wrong after that, you could possibly removing some data.