Save delets record

by jpu   Last Updated August 31, 2018 19:09 PM

in cron (or observer) I'm getting wishlist items and I'm updating them. I have strange behaviour, when I set field value and call save() item record disappears from database.

This is my code:

 $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
 $collection = $objectManager->get('Magento\Wishlist\Model\ResourceModel\Item\Collection')->addFieldToFilter('product_change', ['neq' => 'NULL']);
    ['wishlist' => $collection->getTable('wishlist')],
    "wishlist.wishlist_id = main_table.wishlist_id AND email IS NOT NULL",

 foreach ($collection as $item)

but in foreach, when I change code to this:

  $i = $objectManager->create('Magento\Wishlist\Model\Item')->load($item->getId());

item is correctly saved.

Why this second code works and the first not?

Related Questions