doctrine2 - Doctrine Entity not being included inside the Doctrine Events callback -
i have entities one-to-many relationship
transactionitem -- has many --> payments
edit: included mapping files
payment.yml mapping file
akademia\institution\sales\domain\model\payment\payment: type: entity table: payments repositoryclass: akademia\institution\sales\infrastructure\persistence\doctrine\payment\doctrinepaymentrepository id: id: type: string length: 36 fields: date: type: datetime amount: type: decimal precision: 11 scale: 2 manytoone: transactionitem: targetentity: akademia\institution\sales\domain\model\transactionitem inversedby: payments joincolumn: name: transaction_item_id referencedcolumnname: id
transactionitem.yml mapping
akademia\institution\sales\domain\model\transactionitem: type: entity table: transaction_items repositoryclass: akademia\institution\sales\infrastructure\persistence\doctrine\doctrinetransactionitemrepository id: id: type: string length: 36 fields: productid: type: string column: product_id producttype: type: string column: product_type description: type: string quantity: type: integer price: type: decimal precision: 11 scale: 2 discount: type: decimal precision: 11 scale: 2 paid: type: boolean remarks: type: string nullable: true manytoone: transaction: targetentity: akademia\institution\sales\domain\model\transaction inversedby: lineitems joincolumn: name: transaction_id referencedcolumnname: id onetomany: payments: targetentity: akademia\institution\sales\domain\model\payment\payment mappedby: transactionitem cascade: ['persist'] fetch: eager
when im calling
$transactionitem->pay($amount, $date); $entitymanager->persist($transactionitem); $entitymanager->flush();
transactionitem.php
public function pay($amount, \datetime $date = null) { $payment = new payment( uuid::uuid4()->tostring(), $this, $amount, $date ?? new \datetime()); $this->payments[] = $payment; }
im expecting can transactionitem
on doctrine callbacks here:
services.yml
services: app.doctrine_event_listener: class: appbundle\event\domaineventlistener arguments: ["@app.domain_event_dispatcher"] tags: - { name: doctrine.event_listener, event: postpersist } - { name: doctrine.event_listener, event: postupdate } - { name: doctrine.event_listener, event: postremove } - { name: doctrine.event_listener, event: postflush } app.domain_event_dispatcher: class: appbundle\event\defaulteventdispatcher
the listener:
class domaineventlistener { private $entities = array(); /** @var domaineventdispatcher */ private $dispatcher; public function __construct(domaineventdispatcher $dispatcher) { $this->dispatcher = $dispatcher; } public function postpersist($event) { $this->keepaggregateroots($event); } public function postupdate($event) { $this->keepaggregateroots($event); } public function postremove($event) { $this->keepaggregateroots($event); } public function postflush($event) { /** @var aggregateroot $entity */ vardumper::dump($this->entities);die(); foreach ($this->entities $entity) { foreach ($entity->releaseevents() $anevent) { $this->dispatcher->dispatch($anevent); } } $this->entities = array(); } private function keepaggregateroots($event) { $entity = $event->getentity(); if (!($entity instanceof aggregateroot)) { return; } $this->entities[] = $entity; } }
but when dumping captured entities on postflush vardumper::dump($this->entities);
im getting empty array result.
note: transactionitem
extends aggregateroot
payment not
but @ least im expecting transactionitem
present.
does adding child relationships not include in doctrine events?
how manually tell doctrine transactionitem
should present in postflush event?
edit: dumping inside postupdate not being called.
public function postupdate($event) { $this->keepaggregateroots($event); vardumper::dump('inside postupdate'); vardumper::dump($this->entities);die(); }
Comments
Post a Comment