A question about a persistent last ID for Data Store

Dabbling around with Data Store (maginificent addition to Wappler), I noticed that lastid is very persistent, in that it does not return to 1 when the Data Store has been been deleted.

I feel that there is an underlying reason that I cannot fathom at this stage. Please enlighten me.

image
I managed to get this one to return to 1 (or should it be 0) by deleting by hand.

How did you delete the Data Store? It should reset the lastid when you use the clear method. When using the delete method it does not update the lastid. The lastid is used to generate the $id and can only be reset by clearing the Data Store.

This is what happens when I add a new item to the cart

This is what happens when I delete the cart using dsCart.delete({$id: $id})

As you can see, the Data Store is not deleted, just the contents (which is fine by me). The Data Store still exists and so does the lastid.

This story does not bother me, I just thought that using dsCart delete would have deleted the actual Store.

Edit: I now see what you mean, I’ll try Clearing the Data Store to see what happens. Thanks

2nd Edit: This is what I get when I use the Clear method

The Cart is still there, this time with lastid value of 0.

That is exactly what it should do, when cleared it is just an empty collection. You don’t require the lastid, it is used internally for the $id generation. You should check if the result is empty with the hasItems formatter. Disable the Checkout button with dmx-bind:disabled="!dsCart.data.hasItems()" and perhaps show a bootstrap alert in the dialog that the cart is empty and the user should add something first.

1 Like