   end
 
   def show(conn, %{"id" => id}) do
-    experiment = Experiment |> Repo.get_by(id: id)
+    experiment = Experiment |> Repo.get(id)
 
     case experiment do
       nil ->


      case Map.fetch(experiment_params, "participants_ids") do
        {:ok, participants_ids} ->
          attach_participants_to_experiment(participants_ids, experiment)
      end

      conn

    end
  end

  defp add_participants_to_experiment(participants_ids, experiment) do
    for participant_id <- participants_ids do
      insert_participant(participant_id, experiment.id)
    end
  end

  defp update_participants_in_experiment(new_participants, experiment_id) do
    all_ehp = ExperimentsHasParticipants |> Repo.all(experiment_id: experiment_id)

    saved_participants = all_ehp |> Enum.map(fn(ehp) ->
      ehp.participant_id
    end)

    diff = (new_participants -- saved_participants) ++ (saved_participants -- new_participants)

    Repo.transaction(fn ->

      for participant_id <- diff do
        if Enum.member?(saved_participants, participant_id) do
          remove_participant(participant_id, experiment_id)
        else
          insert_participant(participant_id, experiment_id)
        end
      end

    end)
  end

  defp insert_participant(participant_id, experiment_id) do
    changeset = ExperimentsHasParticipants.changeset(
      %ExperimentsHasParticipants{},
      %{"participant_id" => participant_id, "experiment_id" => experiment_id}
    )

    changeset |> Repo.insert!
  end

  defp remove_participant(participant_id, experiment_id) do
    ExperimentsHasParticipants
    |> Repo.get_by!(
      participant_id: participant_id,
      experiment_id: experiment_id
    )
    |> Repo.delete!
  end

  defp fetch_participants(experiment) do
