How-To UPDATE an Object Values

Hi

I would like to ask, how can I update a specific object which I have a value from one field of it.

like : Update x value(y) where name=m

best regards

For one object (something like update x value(y) where name=m limit 1

$obj = MyObject::getByName('m', 1);
$obj->setValue(y);
$obj->save();

For more objects (so your query update x value(y) where name=m):

$objects = MyObject::getByName('m');
foreach ($objects as $object) {
  $object->setValue(y);
  $object->save();
}

Not tested but should work :smile:

1 Like

thanks , it works, only one chage for other searchers

$obj = DataObject\MyObject::getByName(‘m’, 1);