Hi,
In order to have the Elixir compiler ensure I'm passing reasonable data to `Repo.insert_all/3`, I tried to pass a list of structs as entries, but that doesn't work.
Currently, as per the
documentation, the entries must be either maps or keyword lists.
Example
```elixir
defmodule MySchema do
use Ecto.Schema
schema "my_schema" do
field :user_id, :integer
field :resource, Ecto.Enum, values: [:gold, :silver, :bronze]
field :value, :integer
timestamps()
end
end
```
What I ended up doing to insert 3 rows with type-checking:
```elixir
MySchema
|> Repo.insert_all([
%MySchema{
user_id:
user.id,
resource: :gold,
value: 500,
inserted_at: now
}
|> Map.take(MySchema.__schema__(:fields)),
%MySchema{
user_id:
user.id,
resource: :silver,
value: 700,
inserted_at: now
}
|> Map.take(MySchema.__schema__(:fields)),
%MySchema{
user_id:
user.id,
resource: :bronze,
value: 900,
inserted_at: now
}
|> Map.take(MySchema.__schema__(:fields))
])
```
My proposal is to make it work without the `|> Map.take(MySchema.__schema__(:fields))` part.
Best regards,
Rodolfo