title: elixir map with mixed keys
body: <p>in the Phoenix application, I have a function that takes two maps, and creates two entries in the database via Ecto.Changeset.</p>
  
  <pre><code>def create_user_with_data(user_attrs, data_attrs) do
      name = cond do
          data_attrs["name"] -&gt;
              data_attrs["name"]
          data_attrs[:name] -&gt;
              data_attrs[:name]
          true -&gt; nil
      end
      Ecto.Multi.new()
      |&gt; Ecto.Multi.insert(:user, User.registration_changeset(%User{}, Map.put(user_attrs, :name, name)))
      |&gt; Ecto.Multi.run(:user_data, fn(%{user: user}) -&gt;
          %MyApp.Account.UserData{}
          |&gt; MyApp.Account.UserData.changeset(Map.put(data_attrs, :user_id, user.id))
          |&gt; Repo.insert()
      end)
      |&gt; Repo.transaction()
  end
  </code></pre>
  
  <p>because the keys in these map can be both atoms and lines, I have to check these keys.</p>
  
  <p>but the expression</p>
  
  <pre><code>Map.put(user_attrs, :name, name)
  </code></pre>
  
  <p>will cause an error</p>
  
  <pre><code>** (Ecto.CastError) expected params to be a map with atoms or string keys, got a map with mixed keys: %{:name =&gt; "John", "email" =&gt; "m@gmail.com"}
  </code></pre>
  
  <p>if the keys are strings. </p>
  
  <p>Is there any best practice in dealing with this issue?</p>