Problem with multi-enum field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • azidevnom
    Junior Member
    • Oct 2019
    • 20

    Problem with multi-enum field

    I have an entity (Sale) with a multi-enum field (contractServices). I have been asked to add a new item to this field, and also add this item on some already existing entries.

    So I ran this code in a DataLessJob.

    PHP Code:
    $repository = $this->entityManager->getRDBRepositoryByClass(Sale::class);
    
    foreach (self::IDS as $id) {
        $sale = $repository->getById($id);
        $contractServices = $sale->get('contractServices');
        $sale->set('contractServices', array_unique(array_merge($contractServices, [self::ITEM_NAME])));
        $repository->save($sale, [ SaveOption::SKIP_ALL => true ]);
    }

    It does its job. I checked the database and the item was added to the field just fine.

    The problem comes when now I try to filter this field containing this new item. The updated entries don't show when I filter by this item, even when I am 100% sure is present in the array.

    The weird part is: if I go and manually edit the entry removing this item from the multi-enum array, then save, then edit again and add the item back to the array, then save again, now it shows in the filter.

    I don't see any difference in the database after this manual edit.

    Am I doing something wrong? Did I miss something in my code?
  • yuri
    Member
    • Mar 2014
    • 8439

    #2
    SaveOption::SKIP_ALL skips all hooks. Should not be used unless a developer really knows why the parameter is needed in a particular case.

    To fix existing values, run the command:

    Code:
    php command.php populate-array-values YourEntityType yourField
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    Working...