Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Transaction
- {
- ...
- /**
- *
- * @ORMOneToOne(targetEntity="Transaction")
- * @ORMJoinColumn(name="reverse_transaction_id", referencedColumnName="id")
- * @var FinanceiroEntityMovimentacao
- */
- private $reverseTransaction;
- ...
- }
- CREATE TABLE `transaction` (
- `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
- ...
- `reverse_transaction_id` bigint(20) unsigned DEFAULT NULL,
- ...
- PRIMARY KEY (`id`),
- ...
- KEY `fk_reverse_transaction_idx` (`reverse_transaction_id`),
- ...
- CONSTRAINT `fk_reverse_transaction` FOREIGN KEY (`reverse_transaction_id`) REFERENCES `transaction` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
- ...
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
- /**
- * Consider that hydrate() is a method that hydrates the entity
- * based on the passed $data and the reference to the entity manager
- */
- // Creation of the first transaction
- $dataA = [
- ...
- ];
- $transactionA = new Transaction();
- $transactionA->hydrate($dataA, $entityManager);
- $entityManager->persist($transactionA);
- $entityManager->flush($transactionA);
- // Creation of the second transaction
- // Already pointing to the first one
- $dataB = [
- ...
- 'reverse_transaction' => $transactionA->getId()
- ...
- ];
- $transactionB = new Transaction();
- $transactionB->hydrate($dataB, $entityManager);
- $entityManager->persist($transactionB);
- $entityManager->flush($transactionB);
- // Update of the first transaction to also point
- // to the second one
- // The error occurs here
- $transactionA->setReverseTransaction($transactionB);
- $entityManager->persist($transactionA);
- $entityManager->flush($transactionA);
Add Comment
Please, Sign In to add comment