symfony - Some methods have its returned value persisted only if other fields are changed before PreUpdate -


my budget entity has methods executed on prepersist , preupdate. methods are:

/**  * @return \datetime  */ public function generatenextpaymentdate() {     if ($this->getstartsat() !== null) {         $date = new \datetime($this->getstartsat()->format('y-m-d'));         return $date->add(new \dateinterval('p' . $this->getcheckfor() . 'd'));     } }  /**  * @return decimal  */ public function calculatetotalbudgetprice() {     $totalbudgetprice = 0;      foreach ($this->getitems() $item) {         $totalbudgetprice += $item->getprice();     }      return $totalbudgetprice; }  /**  * @return decimal  */ public function calculateinstallmentrateprice() {     return $this->calculatetotalbudgetprice() / $this->getinstallmentrate(); }  /**  * @orm\prepersist  * @orm\preupdate  */ public function onpreevents() {     $this->setnextpaymentdate($this->generatenextpaymentdate());     $this->setinstallmentrateprice($this->calculateinstallmentrateprice());     $this->settotalbudgetprice($this->calculatetotalbudgetprice()); } 

the methods calculateinstallmentrateprice() , calculatetotalbudgetprice() uses attributes of product entity, collection form inside of budget.

the issue i've noticed these methods have returned value persisted database if modify 1 or more field of budget form. if not, values these 2 methods still correct not changed in base.

i not understand why happens. have missed logic?

if @ documentation preupdate event see info:

changes fields of passed entities not recognized flush operation anymore, use computed change-set passed event modify primitive field values

so, need use setnewvalue() function modify entity, doing like:

$eventargs->setnewvalue('nextpaymentdate', $this->generatenextpaymentdate()); 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -