php - Overwriting field on on entity with a default value -


i have entity field value(that can null). in table have default value. want override entity's value(with 1 defaults table) if it's null.

products +- country_id -+- price -+ |           1  |   100   | |           2  |   null  | +--------------+---------+  defaults +- country_id -+- price -+ |           1 |      10  | |           2 |      99  | +-------------+----------+  // product should load price defaults $product = $productrepository->findoneby(['country_id' => 2]); 

is there symfony allow me this?

maybe though constraints?

constraints not option. may can achieve postload event provided doctrine, (documentation here), this:

public function postload(lifecycleeventargs $args) {     $entity = $args->getentity();      if ($entity instanceof your_entity)     {         if (null == $entity->getmyfield())         {             $entity->setmyfield(new_value);         }     } } 

i didn't try it, haven't tried @ all, think should idea..


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -