I have 2 entities: Issues and Pages. A Issue have a list of Pages. How can I delete all Pages when Issue is deleted (cascade)?
You need to iterate over objects you need to delete and call the API to delete them individually.
Alternatively, you can use the “Bulk delete” API (available only in REST) - scroll down to the “Bulk delete” section:
https://backendless.com/documentation/data/rest/data_deleting_data_objects.htm
Nice, I want to use Bulk delete, but in my example, how can I reference the object link (something like “where=issueId%3Dnull”, for remove all Pages without Issue?
which table has the relation column? Is it in Pages or in Issue?
Issue as a list os Pages.
So then you would send a bulk delete request to the Pages table with the following whereClause:
Issue[pages].objectId is null
Hi. I think I am doing something wrong. Please help me.
He is the curl:
MacBook-Pro-do-Rimolo:bin arimolo$ curl -H application-id:XXXXX -H secret-key:YYYYY -X DELETE -v https://api.backendless.com/v1/data/bulk/Pages?where=Issues[pages].objectId%20is%20null
- Trying 54.88.94.142…
- Connected to api.backendless.com (54.88.94.142) port 443 (#0)
- TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- Server certificate: *.backendless.com
- Server certificate: COMODO RSA Domain Validation Secure Server CA
- Server certificate: COMODO RSA Certification Authority
- Server certificate: AddTrust External CA Root
DELETE /v1/data/bulk/Pages?where=Issues%5Bpages%5D.objectId%20is%20null HTTP/1.1
Host: api.backendless.com
User-Agent: curl/7.43.0
Accept: /
application-id:XXXXX
secret-key:YYYYY
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers: origin, application-id, application-type, content-type, secret-key, request, user-token
< Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Sun, 10 Apr 2016 22:19:13 GMT
< Server: nginx/1.8.1
< Content-Length: 66
< Connection: keep-alive
<
- Connection #0 to host api.backendless.com left intact
Internal server error with id 149921C2-B5DC-D9D5-FF5F-FB7840192900MacBook-Pro-do-Rimolo:bin arimolo$
My Data:
http://support.backendless.com/public/attachments/2ae536cd45487dedb70c2f1e23aa60e5.jpg</img>
I also tried where clauses:
- where=Issues.pages%20is%20null
where=Issues.pages+is+null
where=Issues.pages.objectId%20is%20null
....
Thank you a lot!!
You’re trying to delete all pages which are not related to issues, right?
Right now you do not have any issues at all (the Issues table shows 0 objects). I do not understand what those objects are in the Issues.pages column…
Yes, I can’t understand either. I think the platform should remove the reference.
I just want to replace all pages when I pass the Issues object with new pages (I’m using Java SDK), but when I do it the new Pages objectes are created and the old Pages objects remain without reference. So, I’m trying to remove all Pages related with the Issue before saving the new ones. Do you see?
The curl command you showed deletes Pages objects, but the screenshot shows that you have zero Issues objects. That is why I was asking if the use-case makes sense. What is the expected result here? Deleting all Pages?
Yes, I need to delete all pages of a Issue.
http://support.backendless.com/public/attachments/cbc9d24638ffab7d02df1df85978bad0.jpg</img>
I have deleted all, and now I have just one Issue with 61 pages. I’m trying to delete all pages (with no success), as:
MacBook-Pro-do-Rimolo:bin arimolo$ curl -H application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400 -H secret-key:XXXXXX -X DELETE -v https://api.backendless.com/v1/data/bulk/Pages?where=Issues[pages].objectId=A15AA281-0ECF-CA37-FF22-EBA3D2522300
- Trying 52.23.112.2…
- Connected to api.backendless.com (52.23.112.2) port 443 (#0)
- TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- Server certificate: *.backendless.com
- Server certificate: COMODO RSA Domain Validation Secure Server CA
- Server certificate: COMODO RSA Certification Authority
- Server certificate: AddTrust External CA Root
DELETE /v1/data/bulk/Pages?where=Issues%5Bpages%5D.objectId=A15AA281-0ECF-CA37-FF22-EBA3D2522300 HTTP/1.1
Host: api.backendless.com
User-Agent: curl/7.43.0
Accept: /
application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400
secret-key:XXXXX
< HTTP/1.1 400 Bad Request
< Access-Control-Allow-Headers: origin, application-id, application-type, content-type, secret-key, request, user-token
< Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Mon, 11 Apr 2016 00:53:29 GMT
< Server: nginx/1.8.1
< Content-Length: 46
< Connection: keep-alive
<
- Connection #0 to host api.backendless.com left intact
{“code”:1017,“message”:“Invalid where clause”}MacBook-Pro-do-Rimolo:bin arimolo$
The objectId value must be surrounded by single quotes, like this:
Issues%5Bpages%5D.objectId%3D%27A15AA281-0ECF-CA37-FF22-EBA3D2522300%27
Now Backendless is returning Internal Server Error:
MacBook-Pro-do-Rimolo:bin arimolo$ curl -H application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400 -H secret-key:XXXXXXX -X DELETE -v https://api.backendless.com/v1/data/bulk/Pages?where=Issues[pages].objectId%3D'A15AA281-0ECF-CA37-FF22-EBA3D2522300'
-
Trying 52.23.112.2…
-
Connected to api.backendless.com (52.23.112.2) port 443 (#0)
-
TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
-
Server certificate: *.backendless.com
-
Server certificate: COMODO RSA Domain Validation Secure Server CA
-
Server certificate: COMODO RSA Certification Authority
-
Server certificate: AddTrust External CA Root
DELETE /v1/data/bulk/Pages?where=Issues%5Bpages%5D.objectId%3D%27A15AA281-0ECF-CA37-FF22-EBA3D2522300%27 HTTP/1.1
Host: api.backendless.com
User-Agent: curl/7.43.0
Accept: /
application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400
secret-key:XXXXXX
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers: origin, application-id, application-type, content-type, secret-key, request, user-token
< Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Mon, 11 Apr 2016 01:37:39 GMT
< Server: nginx/1.8.1
< Content-Length: 66
< Connection: keep-alive
<
- Connection #0 to host api.backendless.com left intact
Internal server error with id 493B90A9-A8CF-15B3-FF19-561378AB6B00MacBook-Pro-do-Rimolo:bin arimolo$
The internal error says:
“Table ‘Pages’ is specified twice, both as a target for ‘DELETE’ and as a separate source for data”
Looks like this approach will not work after all.
So, the only way is iterate? I really think that Backendless can improve in this area.
Thank you a lot, Mark.
Try to execute the following request ( same as previous, but url is surrounded with single quotes ):
curl -H application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400 -H secret-key:XXXXXXX -X DELETE -v ‘https://api.backendless.com/v1/data/bulk/Pages?where=Issues%5Bpages%5D.objectId%3D%27A15AA281-0ECF-CA37-FF22-EBA3D2522300%27’
Hi Alexandr,
Tks for your help!
Another error:
MacBook-Pro-do-Rimolo:bin arimolo$ curl -H application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400 -H secret-key:XXXXX -X DELETE -v ‘https://api.backendless.com/v1/data/bulk/Pages?where=Issues[pages].objectId%3D’A15AA281-0ECF-CA37-FF22-EBA3D2522300’’
-
Trying 54.84.253.252…
-
Connected to api.backendless.com (54.84.253.252) port 443 (#0)
-
TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
-
Server certificate: *.backendless.com
-
Server certificate: COMODO RSA Domain Validation Secure Server CA
-
Server certificate: COMODO RSA Certification Authority
-
Server certificate: AddTrust External CA Root
DELETE /v1/data/bulk/Pages?where=Issues%5Bpages%5D.objectId%3D%27A15AA281-0ECF-CA37-FF22-EBA3D2522300%27 HTTP/1.1
Host: api.backendless.com
User-Agent: curl/7.43.0
Accept: /
application-id:6F480FD5-E12D-0CE3-FF32-65E67B9C4400
secret-key:XXXXX
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers: origin, application-id, application-type, content-type, secret-key, request, user-token
< Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE, PATCH
< Access-Control-Allow-Origin: *
< Content-Type: application/json
< Date: Mon, 11 Apr 2016 14:03:59 GMT
< Server: nginx/1.8.1
< Content-Length: 66
< Connection: keep-alive
<
- Connection #0 to host api.backendless.com left intact
Internal server error with id 8F2B0564-CEA5-79FA-FF55-FD6717F81700MacBook-Pro-do-Rimolo:bin arimolo$
Ok, I’ve checked the error, this is a bug on our side.
We shall fix it and this request would work for you after release.
Nice, thank you Alexandr!
Cascade deletion would definitely be useful. Looking forward this feature and, meanwhile, I will use bulk delete.
Would be great to see your roadmap public and online (maybe like this one : http://unity3d.com/unity/roadmap