I am faced with a situation where I have a collection of categories and a separate collection of places, with each place having a foreign key that corresponds to a category ID.
You can find the list of categories in categorie.json: http://pastebin.com/ttumKPf9
Similarly, the list of places can be accessed from place.json: http://pastebin.com/J4bdEiUx
In an attempt to validate if a specific category ID exists, I have modified the create method within the place class. This new implementation involves checking if the provided category ID is present in the category list. If it is found, I trigger the upsert method to insert the data into the place. However, the challenge arises when the upsert method recursively calls the create method, causing a deadlock scenario as the data fails to get inserted without invoking the upsert method.
To address this dilemma and successfully verify and insert the data using strongloop, I seek guidance on overcoming this circular call issue within my script.js file:
module.exports = function(app){
var Place = app.models.place;
var Categorie = app.models.categorie;
Place.create = function(data,callback){
console.log("before searching");
console.log(data.id);
Categorie.findById(data.categorieId, function(err, instance){
console.log("searching")
if(err){
throw err;
}
if(instance == null){
new err;
throw err;
}
console.log("Upsert");
Place.upsert(data, callback);
});
};
};