saveStrategy replace in hasMany

Hi.

I’m doing “patchEntity” to my shopping cart. New shoppingCart does not have all the shoppingCartItems that old shoppingCart has. I want to delete the absent items from db. Everything seems to be ok in code (= no errors), but items are not deleted from db. Changes to items are updated though.

I tried to use


$shoppingCart->setDirty('ShoppingCartItems', true);

and I added saveStrategy to ShoppingCartTable


$this->hasMany('ShoppingCartItems', [
    'foreignKey' => 'shopping_cart_id',
    'saveStrategy' => 'replace'
]);

I’ll get the impression from docs that changing the saveStrategy to replace should delete the extra items.

Example data
Old entity:


     "shoppingCart": {
    	"id": "1",
    	"user_id": "yyy",
    	"shopping_cart_items": [
    		{
    			"id": 53,
    			"shopping_cart_id": "1",
    			"product_id": 1234,
    			"product_code": "1234",
    			"product_name": "Name 1",
    		},
    		{
    			"id": 54,
    			"shopping_cart_id": "1",
    			"product_id": 1235,
    			"product_code": "1235",
    			"product_name": "Name 2",
    		},
    		{
    			"id": 55,
    			"shopping_cart_id": "1",
    			"product_id": 1236,
    			"product_code": "1236",
    			"product_name": "Name 3",
    		}
    	]
    }

New entity:


    "shoppingCart": {
        	"id": "1",
        	"user_id": "yyy",
        	"shopping_cart_items": [
        		{
        			"id": 53,
        			"shopping_cart_id": "1",
        			"product_id": 1234,
        			"product_code": "1234",
        			"product_name": "Name 1",
        		},
        		{
        			"id": 55,
        			"shopping_cart_id": "1",
        			"product_id": 1236,
        			"product_code": "1236",
        			"product_name": "Name 3",
        		}
        	]
        }