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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -