Destroy an object in a Volt store collection

98 views Asked by At

I'm trying to delete an object in a store collection using:

store.widgets.where(code: 'xyz').first.destroy

and get the following result from the promise:

[:@action, :@realized, :@exception, :@value, :@error, :@delayed, :@prev, :@next]

and the object is not deleted/destroyed.

Is this the right way to do it?

2

There are 2 answers

0
balmoral On

The problem was caused by my own (legacy) #destroy method in Object overriding the behaviour of the promise chain from first to destroy.

Can confirm that both

store.widgets.delete(store.widgets.where(code: 'xyz').first)

and

store.widgets.where(code: 'xyz').first.destroy

do work as expected.

0
Jason Southwell On

Try something like this:

store.widgets.delete(store.widgets.where(code: 'xyz').first)

Or if you really want to just delete the first item:

store.widgets.delete_at(0)