A topic that comes back now and then, is how to copy an existing Ecto struct for insertion.
Simply removing the `:id` field is not sufficient, because the Ecto struct contains meta data (e.g. `:loaded`). I run into errors relating to function clauses not matching when trying to insert an existing Ecto struct, even when removing the `:id` ; pretty sure because of the meta data.
This is how I solve the problem in my application:
```
def duplicate(foo) do
data =
foo
|> Map.take(Foo.__schema__(:fields))
|> Map.delete(:id)
struct(Foo, data)
end
```
That seems to work fine. But note how I have to rely on reflection in order to achieve that.
Question/proposition: do you think we can offer a function for copying an existing Ecto struct (to be inserted)?