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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -