       %{participant | :experiment_uuid => ehp.uuid}
     end)
   end
-
-  defp ehp_query(experiment_id) do
-    from ehp in ExperimentsHasParticipants,
-      where: ehp.experiment_id == ^experiment_id,
-      select: ehp
-  end
 end


    if experiment_changeset.valid? do
      participants_ids = experiment_params |> Map.fetch!("participants_ids")

      experiment = experiment_changeset |> Repo.update!

      case update_participants_in_experiment(participants_ids, experiment.id) do
        {:ok, _} ->
          experiment = Experiment.with_participants_and_photos |> Repo.get(id)

          conn
          |> render("success.json", experiment: %{experiment | :participants => participants_with_uuid(experiment)})
      end
    else
      conn

    experiment_changeset = Experiment.changeset(%Experiment{}, experiment_params)

    if experiment_changeset.valid? do
      participants_ids = experiment_params |> Map.fetch!("participants_ids")
      photos_ids = experiment_params |> Map.fetch!("photos_ids")

      experiment = Repo.insert!(experiment_changeset)

      transaction = Repo.transaction(fn ->
        "participant" |> insert_assoc_multiple(experiment.id, participants_ids)
        "photo" |> insert_assoc_multiple(experiment.id, photos_ids)
      end)

      case transaction do
        {:ok, _} ->
          conn
          |> put_status(:created)
          |> render("success.json", experiment: experiment)

        {:error, res} ->
          conn
          |> put_status(:unprocessable_entity)
          |> render("error.json", message: res)
      end

    else
      conn
      |> put_status(:unprocessable_entity)
