Doctrine ORM: How to register several times in the same table using beginTransaction()

Asked

Viewed 130 times

0

How do I register in the same database table using beginTransaction(). Example: Registering various details of a product

   $entityManager->getConnection()->beginTransaction();
   try { 
      ...
      // ultimo id Produto cadastrado
        $ultimo_id = $table->getId()

        $num = array(5,2,3);
        $lote = array(8,6,7);

     // O PROBLEMA é que só cadastra a última (no caso chave [2]). Não entendi
        $this->mais_produto($num[0], $lote[0], $ultimo_id);
        $this->mais_produto($num[1], $lote[1], $ultimo_id);
        $this->mais_produto($num[2], $lote[2], $ultimo_id);

      $entityManager->getConnection()->commit();

      return true;
   }

   } catch (\Exception $e) {

            $entityManager->getConnection()->rollback();
            throw $e;
            return false;

    }

dasIn the function mais_product() is running the Doctrine functions $entityManager->persist($table); $entityManager->flush();

  • 1

    What the function mais_produto ago?

  • records data in the database, using persist() and flush()

  • It was not recording because I was running inside an array. The solution was to use the $entityManager->clear after the commit.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.