Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to delete remote objects? #1

Open
michaelgodshall opened this issue Apr 20, 2012 · 5 comments
Open

How to delete remote objects? #1

michaelgodshall opened this issue Apr 20, 2012 · 5 comments

Comments

@michaelgodshall
Copy link

First of all, thank you for making this project available. I am integrating it with a spine project to allow for offline syncing, and so far I have setup get, create, and update actions that sync local storage with the remote server. However, I have not been able to figure out how to delete objects from the remote server. Calling @item.destroy() removes an item from the list, but it doesn't send a DELETE request to the remote server (even with {remote: true}). Is delete support currently available in atmos2? Can you recommend how it might be implemented for online and offline use? Thanks!

@vojto
Copy link
Owner

vojto commented Apr 21, 2012

Hello! Thanks for trying out Atmos2.

Deleting is not implemented yet, here's one thing you can do:

Atmos.res.execute {method: "delete", path: "/items/#{@item.id}"}, (res) =>
  @item.destroy()

Of course it's just a workaround and I'm planning to implement the deleting functionality (with offline support) soon. I will keep this issue open and come back when there's some progress.

@michaelgodshall
Copy link
Author

Thanks for info!

@michaelgodshall
Copy link
Author

I have the remote delete working now. Here's what it looks like in my Controller.

delete: (e) ->
    options = {collection: "Client", action: "delete", pathParams: {clientID: @item.id}}
    Atmos.instance.resourceClient.execute options, (result) =>
        @item.destroy()

Let me know if you make any progress on the offline support!

@michaelgodshall
Copy link
Author

For some reason my previous delete implementation is no longer working correctly. Basically, it sends the DELETE request, which is successful on the server, but then immediately sends a PUT request with the same data, which seems to recreate the object. Here's the console log:

DELETE http://localhost:8000/api/services/161/ 204 NO CONTENT 292ms
syncing meta object update MetaObject { uri={...}, isChanged=true, isLocalOnly=false}
PUT http://localhost:8000/api/services/161/ 200 OK 441ms
changing id 161 -> 161

Any idea why it's sending a PUT request after DELETE?

@michaelgodshall
Copy link
Author

Here is some additional info after further testing:

@item.destroy

Results in:
PUT http://localhost:8000/api/services/161/ 200 OK
(DELETE not called)

options = {collection: "Client", action: "delete", pathParams: {clientID: @item.id}}
Atmos.instance.resourceClient.execute options

Results in:
DELETE http://localhost:8000/api/services/161/ 204 NO CONTENT
PUT http://localhost:8000/api/services/161/ 200 OK
(PUT still called even though @item.destroy() not called directly)

It seems that @item.destory() is triggering the PUT request, but I'm still trying to isolate where in the code this is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants