I have looking around for too long with no luck. My situation is that i have a bit large table +60 columns which is represented in Doctrine Entity. Working on FosREST and what i want to achieve is that i want to send a JSON with specific data let's say for example
[phone] => new_phone
[name] => new_name
[id] => 1
while like i said the entity contains over 60 columns like address, picture, category, etc...
and the phone, name and id are not what I want to change every time but i want to change some columns each time. So at some time i might want to update phone and name other time i want to change the category third time i want to change category and photo and address so is there anything like this ?
$entity->update($parameters);
where the $parameters are dynamically changed as explained before. ps. i know that i can build a very long function with something like
if(isset($parameters['name']){
$entity->setName($parameters['name']);
}
but with 60 ifs this just sounds idiotic anyone have any other approach ? Thanks
1) If the parameters are named after the attributes (here with underscore annotations), you can do this
2) Same thing with the setters
3) If its not the same name, you can do this :
EDIT : Best approach is number two but you should define a white-list or a black-list in order to avoid the user updating something you don't want him to.