Proposal:
I propose to add an `type:` option to Ecto.Schema.has_many. This would allow one to describe the collection of assocs with an Ecto.Type implementation. The resulting container from a cast and dump would need to implement the Enumerable protocol.
Rationale:
After switching to a fractional indexed for the ordering of associations in my project (almost all things have an indexed and can be sorted in this project), I also made an implementation of an OrderedSet based on the fractional indexing. This works great, but falls apart when interactions are had with the Repo, the assocs coming back would be just a list and not an OrderedSet. Of course, I can recursively convert any assoc to an OrderedSet after doing a preload, but that seems a bit wasteful and tedious to add to every repo function.
Another reason for this is that we have custom types for the `field` macro, but not for assocs. It would be nice to have that option as well. One can image an IdMap which would create a Map of the assocs with the ids as keys, and rows as values.
I have an MVP of this proposal as a personal fork of Ecto here:
https://github.com/Zurga/ecto/tree/has_many_as_3.11.2 . I would have time in the future to implement a more robust version, should this proposal get green light.
Cheers!