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.
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?
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?
Comment