     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)
 
-      case Map.fetch(experiment_params, "participants_ids") do
-        {:ok, participants_ids} ->
-          add_participants_to_experiment(participants_ids, experiment)
+      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
 
-      conn
-      |> put_status(:created)
-      |> render("success.json", experiment: experiment)
     else
       conn
       |> put_status(:unprocessable_entity)


    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

      %{participant | :experiment_uuid => ehp.uuid}
    end)
  end
end
