We have an issue with an Embedded schema (Car) containing a list of Embedded Schemas (Images). When we add or delete images everything is working fine. Now we added Reordering the images using drag’n drop in the Frontend. But these reordering changes are not detected by cast_embed and the order stays the same.
A workaround that works is changing a field on Image (we have a version field, that can be changed). In that case the new order is persisted.
Any idea how to accomplish this reordering without doing hacky workarounds?
Ecto version is 2.1.6 (upgrading is hard right now, since it breaks half of our app, but could be a solution as well)
You should consider adding a position field to the images and order by that. I remember that years ago jQuery had a plugin to reorder elements based on a field as well. So should be well-covered by a frontend library.
Yeah, we thought about that. I guess that is probably the mist stable solution. But it feels odd to put an field to save the order in an ordered list. Right now we just increment a version number when changing order and that works as well.
Sorry to bump this old thread, but the issue is still standing. Both JSON (the backing storage in Postgres) and lists have ordering as part of their semantics, adding a position field is redundant and error prone. This looks like a bug from where I’m looking, but maybe I’m missing something in Ecto (config?) that would make changes to the order of embedded documents persist?