destroy multiple rows y save register in other model

22 views
Skip to first unread message

Edwin Dennis

unread,
Aug 3, 2016, 2:10:31 PM8/3/16
to sails.js
I have a model called POST and another called COMMENTS, I implement softDeletes follows, also believes more 2 models called oldPost and oldComments.

the process is the following

1. delete a post (destroy)
2. within beforeDestroy model performed a populate POST (post -> Comments)
3. try to remove all comments relating to the POST
4. Comments within the model have a afterDestroy keeping that comment eliminated in the oldComments model, so try to implement softdeletes
5. after all this process in the model afterDestroy Post I think the same post but in the model oldPost

but it does not work in step 3 when I'm inside POST beforeDestroy model and try to remove all comments related to this post I get a message "Already callback was called."

is the model Comments afterDestroy because inside is where I think the comment but in the model oldComments
 
how can I solve that?

Ryan Emberling

unread,
Aug 22, 2016, 11:02:06 AM8/22/16
to sails.js
Have you considered using Promises? I am relatively new to node.js, and I had an enormous amount of difficulty managing my gazillions of asynchronous callbacks until I started using Promises (I use bluebird.js). I haven't used the sails lifecycle handlers structure. Maybe you would have more luck using sails services to define some helper functions that you could call (perhaps using promises to handle the flow of handlers)?
Reply all
Reply to author
Forward
0 new messages