Under some circumstances, Thelia duplicates a cart when re-creating a user session (see Thelia\Action\Cart::manageCartDuplicationAtCustomerLogin()). The original cart items are deleted from the database during this process (see Thelia\Model\Cart::duplicate()). As you have a DELETE CASCADE on your FK, the related rows in your table are also deleted.
Removing the DELETE CASCADE from your FK is not the proper solution, as you have to attach your data to the duplicated cart items. The proper solution is to create a service that handles the TheliaEvents::CART_ITEM_DUPLICATE to manage cart items duplication.
For example, let's say that your table is CartRelatedData.
...
class YourEventManager implements EventSubscriberInterface
{
public function cartDuplicateItem(CartItemDuplicationItem $event)
{
$list = CartRelatedDataQuery::create()->findByCartItemId($event->getOldItem()->getId());
/** @var CartRelatedData $original */
foreach ($list as $original) {
// Duplicate our data...
$copy = new CartRelatedData();
$original->copyInto($copy);
// ... and attach it to the new cart item
$copy
->setCartItemId($event->getNewItem()->getId())
->save();
}
}
public static function getSubscribedEvents()
{
return [
...
TheliaEvents::CART_ITEM_DUPLICATE => ['cartDuplicateItem', 130 ],
...
];
}
}
Be sure to declare the YourEventManager class in the config.xml file of your module, and clear your cache.
This way, the item attached to the original cart item is deleted via the FK (this is fine), and a new item is created and attached to the duplicated cart item.