I have a page that has multiple AJAX Calls to the server. Now, I am mocking the data with Mirage for testing purpose. For that, I am using Factories.
I have factories for all the models being used during the page render. All the models have many relationships, few models have hasMany and belongsTo, the other models have hasMany alone.
I came across in the net to use aftercreate hook for these kind of associations.
My doubt is :
Model author.js in mirage has :
author: hasMany('post'),
afterCreate(a, server) {
server.create('b', {a});
}
Similarly, Model post.js in mirage has :
author: belongsTo(),
aftercreate(b, server) {
server.create('a', {post});
}
My doubt is, won't it be a recursive calls, after each afterCreate hook, the other model is getting instantiated, and simultaneously calls the other afterCreate and so on?
What is the best way to handle these kinds of relationship issues with mirage?
Thanks in Advance!
Aucun commentaire:
Enregistrer un commentaire