2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Deleting detail records when a master record is deleted

I have two collections, athletes and scores. scores collection has a pointer to an athlete Id. When an athlete is deleted, I want to delete all the scores that are associated with that athlete. how do i do it? Is there a way to cascade delete like in a MasterDetail relationship?

I have three services created. DeleteAthleteService, QueryScoresService, DeleteScoreService. On the click of a delete button, i have a javascript that asks for a confirmation and then invokes the DeleteAthleteService. so far so good. How do I also go and delete the scores? If I query the scores using the QueryScoresService and store the array of Score Ids in a collection/list and put it in the local storage. Is there a way to invoke the DeleteScoreService with a collection instead of one id at a time? Also, how do I invoke the DeleteScoreService with an id from javascript?

Thanks

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Deleting detail records when a master record is deleted

Hello!
[quote:]with a collection instead of one id at a time[/quote]no, you can delete only one at a time[quote:]I invoke the DeleteScoreService with an id from javascript[/quote] please take a look here https://getsatisfaction.com/apperyio/...

2fas2c
Posts: 0
Joined: Mon Dec 16, 2013 11:43 pm

Deleting detail records when a master record is deleted

In my QueryService, do i need to map the output to anything? Can i just write my code to process the response text to store the scoreids into localStorage? For some reason, nothing in my complete event gets processed.

code
On button click:
if (confirm("Are you sure you want to delete?)) {
queryScoreService.execute();
alert("Querying scores complete");
deleteAthleteService.execute();
alert("Deletion completed");
}
On QueryService Complete
alert(jqXHR.responseText);
if (jqXHR.responseText != "[]") {
var scores = JSON.parse(jqXHR.responseText);
if (scores != null) {
alert("Deleting " + scores.length + " scores");
// iterate through the scores array
for (var i = 0; i < scores&#46;length; i++) {
var scoreId = scores&#46;_id;
deleteScoreService&#46;execute({"data":{"object_id":scoreId}});
}
}
/code
None of my alerts in QueryServiceComplete show up. What am i doing wrong?
Thanks

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Deleting detail records when a master record is deleted

Hello! Please check in console is the service executed? Are there any errors? You can use success event instead complete - all data is parsed into data variable

Return to “Issues”