 
   defp insert_question_and_tags(changeset) do
     Repo.transaction(fn ->
-      case (Repo.insert(changeset) |> insert_tags(changeset.tags)) do
+      case (Repo.insert(changeset) |> insert_tags(changeset)) do
         {:error, changeset} ->
           Repo.rollback(changeset)
         {:ok, question, tags} ->
-          {:ok, question, tags}
+          Map.merge(question, %{tags: tags})
       end
     end)
   end
 
   defp insert_tags({:error, changeset}, _), do: {:error, changeset}
-  defp insert_tags({:ok, question}, tags_id) do
+  defp insert_tags({:ok, question}, %{changes: changes}) do
     tag_id_to_changeset = fn tag ->
-      QuestionTag.changeset(%{"tag_id" => tag.id,
-                              "question_id" => question.id,
-                              "required" => tag.required})
+      QuestionTag.changeset(Map.merge(tag, %{"question_id" => question.id}))
     end
 
     insert_changeset = fn

    changeset = Question.changeset(%Question{}, question_params)

    case insert_question_and_tags(changeset) do
      {:ok, question, tags} ->
        question = question
        |> Map.put(:tags, tags)

        conn
        |> put_status(:created)


  def update(conn, question_params) do
    question = conn.assigns[:question]
    |> Repo.preload(:question_tags)

    changeset = Question.changeset(
      Map.merge(question, %{tags: question.question_tags}),
      question_params)

    case Repo.update(changeset) do
      {:ok, question} ->
