Page 1 of 1

Deleting detail records when a master record is deleted

Posted: Thu Mar 06, 2014 8:58 pm
by 2fas2c

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


Deleting detail records when a master record is deleted

Posted: Thu Mar 06, 2014 9:10 pm
by Maryna Brodina

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/...


Deleting detail records when a master record is deleted

Posted: Fri Mar 07, 2014 1:54 pm
by 2fas2c

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


Deleting detail records when a master record is deleted

Posted: Fri Mar 07, 2014 6:11 pm
by Maryna Brodina

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