title: Insert multiple rows at once with Ecto. "protocol Enumerable not implemented for #Ecto.Changeset"
body: <p>I have two tables. A table of <code>topics</code> which <code>has_many</code> <code>tweets</code>. My table of <code>tweets</code> <code>belongs_to</code> a <code>topic</code>. </p>
  
  <p>Topic Schema: </p>
  
  <pre><code>defmodule Sentiment.Topic do
    use Sentiment.Web, :model
  
    schema "topics" do
      field :title, :string
  
      has_many :tweets, Sentiment.Tweet
    end
  
    def changeset(struct, params \\ %{}) do
      struct
      |&gt; cast(params, [:title])
      |&gt; validate_required([:title])
    end
  end
  </code></pre>
  
  <p>Tweet Schema:</p>
  
  <pre><code>defmodule Sentiment.Tweet do
    use Sentiment.Web, :model
  
    schema "tweets" do
      field :message, :string
      belongs_to :topic, Sentiment.Topic
  
    end
  
    @doc """
    Builds a changeset based on the `struct` and `params`.
    """
    def changeset(struct, params \\ %{}) do
      struct
      |&gt; cast(params, [:message])
      |&gt; validate_required([:message])
    end
  end
  </code></pre>
  
  <p>I am attempting to insert a <code>topic</code> into my table, followed by 500 <code>tweets</code> after I run a twitter search for that topic. </p>
  
  <p>In my controller, I use <code>Ecto.Multi</code> to group my repo operations, however, each time I run my operation I get an error <code>protocol Enumerable not implemented for #Ecto.Changeset&lt;action: nil, changes: %{message: "\"aloh....</code> </p>
  
  <p>This is how I am attempting to insert my topic first, obtain it's id, and then insert a tweet message with the associated id with one transaction. </p>
  
  <pre><code> def create(conn, %{"topic" =&gt; topic}) do
      # create a topic changeset
      topic_changeset = Topic.changeset(%Topic{}, topic)
  
      # obtain a list of tweet messages: ["hello", "a tweet", "sup!"]
      %{"title" =&gt; title} = topic
      all_tweets = title
      |&gt; Twitter.search
  
  # create an Ecto.Multi struct.
  multi =
    Ecto.Multi.new
    |&gt; Ecto.Multi.insert(:topics, topic_changeset) #insert topic
    |&gt; Ecto.Multi.run(:tweets, fn %{topics: topic} -&gt;
      changeset_tweets = all_tweets
      |&gt; Enum.map(fn(tweet) -&gt;
        %{topic_id: topic.id, message: tweet}
      end)
  
      Repo.insert_all(Tweet, changeset_tweets)
  
    end)
  
        # Run the transaction
        case Repo.transaction(multi) do # ERROR HERE!
          {:ok, result} -&gt;
            conn
            |&gt; put_flash(:info, "Success!")
            |&gt; redirect(to: topic_path(conn, :index))
          {:error, :topics, topic_changeset, %{}} -&gt;
            conn
            |&gt; put_flash(:error, "Uh oh...")
            |&gt; render("new.html", changeset: topic_changeset)
          {:error, :tweets, topic_changeset, %{}} -&gt;
            conn
            |&gt; put_flash(:error, "Something really bad happened...")
            |&gt;render("new.html", changeset: topic_changeset)
        end
    end
  </code></pre>
  
  <p>How can I <code>insert_all</code> about 500 rows in one transaction using Ecto.Multi?</p>
  
  <p><strong>Update</strong>
  I have converted the list of changesets into a list of maps and my error has changed to something even more confusing. </p>
  
  <p><a href="https://i.stack.imgur.com/ka5Ws.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ka5Ws.png" alt="error"></a>
  <a href="https://i.stack.imgur.com/XcUTO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XcUTO.png" alt="what I am trying to insert"></a></p>